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