Hi All,
I have a code as detailed below which is used to insert a record in one table. However, I need the primary key of the added record and use it elsewhere.
_invoice.Datecreated = DateTime.Now;
_invoice.CustomerInvoiceStatus = CustomerInvoiceStatus.Confirmed;
_invoice.InvoiceTotal = selectedGatePassDespatch.TotalValue;
_invoice.InvoiceReceiptTotal = selectedGatePassDespatch.TotalValue;
_invoice.InvoiceBalance = selectedGatePassDespatch.TotalValue;
_invoice.VatRate = selectedVatRate.Percentage;
_invoice.Posted = true;
_invoice.CustomerContactRelationId = selectedGatePassDespatch.CustomerContact.ContactId;
_invoice.ChartAccountId = selectedStockItem.ChartAccountId;
InvoicebindingSource.EndEdit();
_invoiceService.Insert(_invoice);
So How do I get it Please.
Thanks.
Peter.
Vinay SinghPosted Jun 30, 2016, 4:53 AM
For detail you can check the links
http://stackoverflow.com/questions/5212751/how-can-i-get-id-of-inserted-entity-in-entity-framework
http://stackoverflow.com/questions/16954767/get-record-id-in-entity-framework-after-insert
http://stackoverflow.com/questions/8435462/get-auto-identity-key-after-insert-via-efhttps://dzone.com/articles/how-return-id-field-after
Peter DzuyaPosted Jun 30, 2016, 5:18 AM
Peter DzuyaPosted Jun 30, 2016, 4:39 AM
Vinay SinghPosted Jun 30, 2016, 4:35 AM