简体   繁体   English

C#Azure应用服务中的ApiController在多个相关表中具有CRUD操作

[英]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.

相关问题 从MVC C#中的单个视图对不同表中的多个相关记录进行CRUD操作 - CRUD operations for multiple related records in different tables from single view in MVC C# 更新/编辑C#CRUD操作中的条目 - Update/Edit an Entry in C# CRUD Operations C# 在 Controller 中实现 CRUD 操作 - C# Implementing the CRUD operations in Controller MongoDB C#驱动程序在Azure cosmos dB模拟器中执行CRUD操作 - MongoDB C# Drivers to do CRUD operations in Azure cosmos dB Emulator 如何在 c# asp.net 中使用 crud 操作创建 windows 服务 - how to create windows service using crud operations in c# asp.net 网络(Azure移动服务)操作的C#+ WinRT + Monogame线程 - C# + WinRT + Monogame threading for network (Azure Mobile Service) operations C#ApiController HttpPost - C# ApiController HttpPost 将具有多个相关表的DataSet批量插入SQL Server C# - Bulk Insert DataSet with multiple related tables into SQL Server C# C#SDK CRUD操作的正确返回类型是什么? - What is the proper return type for an C# SDK CRUD operations? .NET C#CRUD操作有效,但永远不会在数据库中更新 - .NET C# CRUD operations work but never gets updated in the Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM