我在文档中找不到有关此的任何信息,所以我会在这里询问。微风如何处理数据库列默认值?我的数据库中需要列,但在数据库列定义中也为这些列提供了默认静态值。通常,我可以将 null 插入这些列,新记录将获得默认值。但是,breeze 似乎不知道数据库列默认值,并且这些列中具有 null 的实体在保存时无法验证。
谢谢, 马蒂亚斯
我在文档中找不到有关此的任何信息,所以我会在这里询问。微风如何处理数据库列默认值?我的数据库中需要列,但在数据库列定义中也为这些列提供了默认静态值。通常,我可以将 null 插入这些列,新记录将获得默认值。但是,breeze 似乎不知道数据库列默认值,并且这些列中具有 null 的实体在保存时无法验证。
谢谢, 马蒂亚斯
This was fixed in Breeze 1.4.6 ( or later), available now.
There is currently in a bug in Breeze that should be fixed in the next release, out in about week. When this fix gets in then breeze will honor any defaultValues it finds in the EntityFramework data model.
One problem though is while it is easy to get 'defaultValues' into a Model First Entity Framework model via the properties editor, it's actually difficult to get it into a Code First EF model, unless you use fluent configuration. Unfortunately, EF ignores the [DefaultValue] attribute when constructing Code First model metadata.
One workaround that you can use now is to poke the 'defaultValue' directly onto any dataProperty. Something like:
var customerType = myEntityManager.metadataStore.getEntityType("Customer");
var fooProperty = customerType.getProperty("foo");
fooProperty.defaultValue = 123;
尝试通过将StoreGeneratedPattern = "Computed"属性添加到数据库中具有默认值的列来编辑 edmx xml。
编辑: 实际上,在编辑 xml 之前,请尝试在模型编辑器本身中将StoreGeneratedPattern属性设置为Computed。