一、聚合函数查询
double sum = 0; using (xxxEntities db = new xxxEntities()) { sum = db.userinfo.AsNoTracking().Where(d => d.id==id).Sum(m => (double?)m.money).GetValueOrDefault(); } return sum;
二、删除操作
int result = 0; if (id > 0) { using (gghdbEntities db = new gghdbEntities()) { var data = db.quote.Where(d => d.id == id).FirstOrDefault(); db.quote.Remove(data); db.SaveChanges(); result = 1; } } return result;
三、执行事物(Net4.0以上版本支持)
using (xxxEntities db = new xxxEntities()) { using (TransactionScope transaction = new TransactionScope()) { //操作,出错自动回滚 //提交事务 transaction.Complete(); } }
需要添加引用:using System.Transactions;