2016-07-25 44 views
0

我想将这些主键插入到我的其他表中,还是有其他简单的方法一次添加多个数据?数据库不受影响,作为回报,我得到的主键值为零

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

回答

0

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

+0

谢谢..我错过了.. – UnNamed

相关问题