Linq To Sql - SQL Default Constraint Problem

懵懂的女人 提交于 2019-12-20 01:38:12

问题


I have a USER table in database. The table has a RegistrationDate column which has a default constraint as GETDATE().

When using LINQ, I don't provide any data for RegistrationDate column to make it default. But SQL Server raises error. I think LINQ tries to insert NULL into the column.

How can I make LINQ not to try to insert in the column RegistrationDate, because it has default value?


回答1:


Set Auto Generated Value property to true in the designer.

Or IsDbGenerated="true" in .dbml file.




回答2:


I am not 100% sure, but you could make the property read-only in the DBML designer.



来源:https://stackoverflow.com/questions/2743797/linq-to-sql-sql-default-constraint-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!