【发布时间】:2015-04-06 08:16:59
【问题描述】:
我无法使用 AddObject 方法将数据插入到使用 Entity 框架版本 5.0 的数据库中。请帮我完成。
List<Error> errorlist = new List<Error>();
errorlist.Add(new Error{ Authentication="From", dateTime=DateTime.Now.ToString(), messageText="xyz", server="10.11.12.217", Username="John"});
errorlist.Add(new Error{ Authentication="From", dateTime=DateTime.Now.ToString(), messageText="xyz", server="10.11.12.217", Username="George"});
using (TransactionScope transe = new TransactionScope())
{
using (SportsEntities bulk = new SportsEntities())
{
ErrorLog error = new ErrorLog();
for (int i = 0; i < errorlist.Count; i++)
{
error.AUTHENTICATION_MODE = errorlist[i].Authentication;
error.DATE_ARRIVAL = errorlist[i].dateTime;
error.MESSAGE = errorlist[i].messageText;
error.SERVER_DETAILS = errorlist[i].server;
error.USERNAME = errorlist[i].Username;
bulk.ErrorLogs.AddObject(error);
}
bulk.SaveChanges();
}
transe.Complete();
}
}
【问题讨论】:
-
试试
bulk.ErrorLogs.Add(error);(只是.Add()- 不是.AddObject()).....
标签: asp.net c#-4.0 entity-framework-5