数据库不受影响,作为回报,我将主键作为零值

时间:2016-07-25 15:57:29

标签: c# linq

我想在我的其他表中插入这些主键,还是有其他一种简单的方法可以一次添加多个数据?

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
    }
}

1 个答案:

答案 0 :(得分:0)

在读取返回值之前,必须在DbContext上调用SubmitChanges()方法。 SubmitChanges方法将数据写入数据库。

相关问题