2016-07-25 4 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

関連する問題