1
我無法使用AddObject方法將數據插入數據庫使用實體框架版本5.0。請幫助我通過。無法使用AddObject方法將數據插入數據庫使用實體框架版本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()')..... – 2015-04-06 08:19:21