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();
还没有评论,来说两句吧...