[英]ApiController in C# Azure App Service with CRUD operations in multiple related tables
I need to write an .NET C# ApiController in Azure App Service to insert (update/delete) into multiple related tables. 我需要在Azure App Service中编写一个.NET C#ApiController,以将(更新/删除)插入到多个相关表中。 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.
例如,在表A中插入一条记录,从表A中获取新插入的记录ID,然后在表B中插入使用该RecordID引用到表A的多条记录。
How can I manage that? 我该如何处理?
Thanks, Uwe 谢谢,乌威
You will be creating a web api and hosting it in azure app service( api app). 您将创建一个Web api并将其托管在azure应用程序服务(api应用程序)中。 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.
插入表A并从那里获取记录ID并执行其他CRUD操作。 Firstly if you are doing it via stored procedure or entity framework there are options to get the last inserted record id for eg
首先,如果您是通过存储过程或实体框架进行操作,则可以选择获取最后插入的记录ID,例如
Get Record ID in Entity Framework after insert 插入后在Entity Framework中获取记录ID
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
从Entity Framework 6开始,您将拥有此功能
https://msdn.microsoft.com/en-us/data/dn456843.aspx https://msdn.microsoft.com/zh-CN/data/dn456843.aspx
You can also do the same in ado.net or having transactions within stored procedure. 您也可以在ado.net中执行相同操作,或者在存储过程中进行事务处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.