[英]Is it possible to insert multiple child records using the entity framework?
Using entity framework.使用实体框架。 Is it possible to insert multiple child records.
是否可以插入多个子记录。 At the moment I am iterating through a list and adding to entity object, but only one/the last object is saved to the database.
目前我正在遍历一个列表并添加到实体 object,但只有一个/最后一个 object 保存到数据库中。 Should I just create a sproc, or is this possible with EF?
我应该只创建一个存储过程,还是使用 EF 可以做到这一点? eg
例如
//dc = datacontext
var fileList = Session["FileNames"];
string[] sA = fileList.ToString().Split('|');
for (int i = 0; i < sA.Count(); i++)
{
wcc.ID = id; //which has been supplied through a previous
//dc.SaveChanges
wcc.FileName = sA[i];
dc.AddTotbObject(wcc);
}
dc.SaveChanges();
dc.Dispose();
You're only ever adding a single instance.您只添加一个实例。 You'll need to do something along these lines within your loop:
您需要在循环中执行以下操作:
wcc = new tbObject();
wcc.ID = id;
wcc.FileName = sA[i];
dc.AddTotbObject(wcc);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.