我想在我的另一个表中插入这些主键,或者有其他简单的方法一次添加多个数据吗?
using(Dbcontext)
{
list<dbTable> dbTbl = new list<dbTbl>();
list<long> RetrunedPrimaryKeys = new list<long>();
for(int i=0; i<datafromPresentationlayer.count;i++)
{
dltable tbl = new dbtable();
tbl.name = datafromPresentationlayer[i].name;
tbl.address = datafromPresentationlayer[i].address
dbTbl.add(tbl);
}
Dbcontext.dbTable.InsertAllOnSubmit();
for(int i=0; i< datafromPresentationLayer.count;i++)
{
RetrunedPrimaryKeys.add(dbTbl[i].primarkeycolumn); // here i get all the primary keys as zero and in database there is not a single entry of these record
}
}
在读取返回值之前,必须调用DbContext上的SubmitChanges()方法。SubmitChanges方法将数据写入数据库。