EF简单的增删改查


 JSDEntities edm = new JSDEntities();

 

            //select

            var temp = from p in edm.accounts_top_up

                       where p.ID == 18410

                       select p;

            accounts_top_up atu = temp.Single();

 

            //update

            accounts_top_up at = new accounts_top_up() { USER_ID = 18412, ID = 18412 };

            DbEntityEntry<accounts_top_up> entry = edm.Entry<accounts_top_up>(at);

            entry.State = System.Data.EntityState.Unchanged;  

            entry.Property("USER_ID").IsModified = true;

            edm.SaveChanges();

 

            //add

            accounts_top_up a = new accounts_top_up() { USER_ID = 18412, ID = 18412 };

            edm.accounts_top_up.Add(a);

            edm.SaveChanges();

 

            //delete

            edm.Entry<accounts_top_up>(new accounts_top_up() {  ID = 18411}).State = EntityState.Deleted

            edm.SaveChanges();

2:模糊查询
actualContext.PU.Where(a=>a.ErrorReason.Contains("sdfsdf"))使用Contains关键字

3:   var list = from entity in actualContext.PSI   where (string.IsNullOrEmpty(entity.QYPortEN) || entity.QYPortEN == priceinfo.QYPortEN)      select entity;

4:where if

 where ((sortBy == "Buy equipment") ? entity.Type == "Sell" : true) &&  ((sortBy == "Sell equipment") ? entity.Type == "Buy" : true)
分组查询:

entities db=new entities();

var rslt=from u in tb group u by u.name into g

select new { subject=g.key,average=g.average(u=>u.score),sum=g.sum(a=>a.score)}

var list=rslt.tolist();

分组方法二:

var list=ote.score.GroupBy(a=>a.SubName).Select(a=>new{ subject=a.key,average=a.average(b=>b.score) }).tolist();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值