0

I need to write an .NET C# ApiController in Azure App Service to insert (update/delete) into multiple related tables. For example insert a record in Table A, get the new inserted record id from Table A and insert multiple records in Table B that are referenced to Table A with this RecordID.

How can I manage that?

Thanks, Uwe

Uwe Becker
  • 123
  • 7

1 Answers1

0

You will be creating a web api and hosting it in azure app service( api app). Within the code for that given method you will the implementation within which you will make the database calls. Insert in table A and get the record ID from there and doing other CRUD operations. Firstly if you are doing it via stored procedure or entity framework there are options to get the last inserted record id for e.g.

Get Record ID in Entity Framework after insert

Since all the db operations have to happen together or must be rolled back you should be doing it within transactions. From Entity framework 6 onwards you have this capability

https://msdn.microsoft.com/en-us/data/dn456843.aspx

You can also do the same in ado.net or having transactions within stored procedure.

Community
  • 1
  • 1
Aravind
  • 4,125
  • 1
  • 28
  • 39