实体模型 - 插入时如何使用数据库的默认列值 [英] Entity Model - How to use Database's Default Column Values while inserting
问题描述
我从DB生成实体模型。
我的数据库有各种表&安培;让我们来看一个表用户的例子
它有字段id,name,email,created_on,is_active,is_on_leave
is_active和on_leave属性的默认值在db中默认为0(零)
但是,当我尝试使用实体模型在此表中插入记录时,它将在这些字段中保存NULL。如何避免这种情况?我不想从我的页面设置一个值,想要使用DB中提到的值。
我该如何实现?
此列可以为空。在设计器中右键单击属性,选择属性并设置StoreGeneratedPatern属性以在属性窗口中计算。
我发现类似的问题:
在EF中设置默认值设计师日期时间
I am using SQLServer 2008, WebForms, C#, Frameowrk 3.5, Entity Framework 1 I generated entity model from DB.
My DB has various tables & lets take example of one table user It has fields id, name, email, created_on, is_active, is_on_leave default values for is_active and on_leave properties are default to 0 ( zero ) in db
But When I try to insert a record in this table using entity model, it saves NULL in these fields. How to avoid this? I don't want to set a value for them from my page and want to use the one mentioned in DB.
How can I achieve that?
This columns can be nullable. Right click property in designer, choose properties and set StoreGeneratedPatern for property to computed in the property window. I found similar question: Set default value in EF designer datetime
这篇关于实体模型 - 插入时如何使用数据库的默认列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!