2013-02-14 110 views
1

我有一個新的插入,然後我需要得到剛插入獲取範圍身份

 var provider = new tbl_Provider 
     { 
      provider_Name = txt_ProviderName.Text, 
      provider_Contact = txt_ProviderContactName.Text, 
      provider_Address1 = txt_Address1.Text, 
      provider_Address2 = txt_Address2.Text, 
      provider_Address3 = txt_Address3.Text, 
      provider_Postcode = txt_Postcode.Text, 
      provider_Telephone = txt_Telephone.Text, 
      provider_Deleted = false 
     }; 

     //provider.tbl_ProviderDetails. = lst_ServiceAreas.SelectedValue;      

     // Insert 
     // ====== 
     _db.tbl_Providers.InsertOnSubmit(provider); 

     // Save 
     // ==== 
     _db.SubmitChanges(); 

項目的ID我怎麼會Linq中做到這一點。

我以前用選擇的範圍標識完成它,但我正在嘗試Linq這個項目。

回答

1

試試這個方法。更多info

 int Id = 0; 
     provider = new tbl_Provider 
     { 
      provider_Name = txt_ProviderName.Text, 
      ... 
     }; 
     // Insert 
     _db.tbl_Providers.InsertOnSubmit(provider); 

     // Save 
     _db.SubmitChanges(); 
     Id = provider.ProviderId;