标签:插入 arm ges class 数据 mvc mod try span
#region 批处理
///
///两增一删一改
///
public void Save(){
//新增参一
Parameter parm = new Parameter()
{
ParaName =“参一”,
ParaNo = “0004”,
ParaValue = “100”
};
//Added
dbNe.Parameter.Add(parm);
//新增参二
Parameter p2 = new Parameter(){
ParaName ="参二",
ParaNo = "0005",
ParaValue = "100"
};
DbEntityEntry<Parameter> entry = dbNe.Entry<Parameter>(P2);
entry.State = System.Data.EntityState.Added;
//修改数据
Parameter PEdit = new Parameter(){
ParaNo ="00003",
ParaName = "参数三"
};
DbEntityEntry<Parameter> entryEdit = dbNe.Entry<Parameter>(PEdit);
entryEdit.State =System.Data.EntityState.Unchanged;
entryEdit.Property("ParaName").IsModified = true;
//删除操作
Parameter parm = new Parameter(){
ParaNo = "00008"
};
dbNe.Parameter.Attach(parm);
//Deleted
dbNe.Parameter.Remove(parm);
//保存
dbNe.SaveChanges();
}
#endregion
//一次插入50条数据
public void AddTen(){
for(int i=1;i<=50;i++){
Parameter p = new Parameter(){
ParaNo = "0100"+i,
ParaName = "参数"+i,
ParaValue = "100"+i
}
dbNe.Parameter.Add(p);
}
dbNe.SaveChanges();
}
MVC ---- EF批处理
标签:插入 arm ges class 数据 mvc mod try span
原文地址:http://www.tofacebook.com/post/17034