简体   繁体   English

如何使用Linqpad插入具有指定主键的记录?

[英]How do I use Linqpad to insert record with specified primary key?

So when I run the following, the role is inserted but the ID column is auto generated. 因此,当我运行以下命令时,将插入角色,但会自动生成ID列。 How do I stop this from happening when using Linqpad? 使用Linqpad时,如何防止这种情况发生?

Roles.InsertOnSubmit(new Role(){ID = 26, Name = "TheRole", Created = DateTime.Now, Updated = DateTime.Now});    
SubmitChanges(); 

The ID column is set to AUTO INCREMENT in database, you can't override that from LINQ, you have to modify your database table schema to remove AUTO INCREMENT from table. 在数据库中,ID列设置为AUTO INCREMENT,您不能从LINQ覆盖它,必须修改数据库表架构以从表中删除AUTO INCREMENT。

You can also enable IDENTITY_INSERT if you are using ADO.Net, see this question for related SQL details. 如果您使用的是ADO.Net,也可以启用IDENTITY_INSERT ,有关SQL详细信息,请参阅此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LINQPad:如何使用SQLite整数主键自动分配 - LINQPad: How to use SQLite integer primary key automatic assignment 如何在一次通话中插入带有前一条记录键的记录? - How do I insert a record with the key of the previous record in one call? 如何在插入失败时获取冲突行的主键? - How do I get primary key of colliding row on failed insert? 如何使用LINQ和C#插入记录并返回该记录的主键 - How to insert a record with LINQ and C# and return the Primary Key of that record INSERT INTO Firebird 如何使用主键的自动增量? - How do INSERT INTO Firebird, with autoincrement for the primary key? 如何在 Visual Studio 中使用 LINQPad 脚本? - How do I use LINQPad scripts in Visual Studio? LINQPad如何与第三方插件一起使用? - How do I use LINQPad with third party plugins? 如何在ms访问数据库中插入带主键的记录c# - How to insert a record with a primary key in ms access database c# 如何通过记录的主键删除记录? 使用Web API 2.获取404 - How do I delete a record by its primary key? using web api 2. getting 404 如何使Entity Framework 6(DB First)显式插入Guid / UniqueIdentifier主键? - How do I make Entity Framework 6 (DB First) explicitly insert a Guid/UniqueIdentifier primary key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM