为什么“DatabaseGeneratedOption.None”存在? [英] Why does the `DatabaseGeneratedOption.None` exist?
问题描述
这与 Property(()=> p).HasDatabaseGeneratedOption()
调用一起使用。是否可能关闭默认的DB值生成?
EF使用 DatabaseGeneratedOption
确定如何处理新实体的键列的值。如果 DatabaseGeneratedOption
是 Identity
EF知道属性设置的值可以被忽略,应该从数据库中使用。如果 DatabaseGeneratedOption
是无
EF将把属性的值作为键列的值插入数据库。在代码首先 - 当Code First约定找到一个int属性,该属性可以是给定实体的关键属性时,它们默认将这个列配置为标识列(意思是数据库将生成键列/属性的值)。 DatabaseGeneratedOption.None
允许你覆盖这个,如果你想自己设置键值。
This is used with the Property(() => p).HasDatabaseGeneratedOption()
call. Is is perhaps to turn off default DB value generation?
EF uses DatabaseGeneratedOption
to figure out what to do with the value of a key column for new entities. If the DatabaseGeneratedOption
is Identity
EF knows that the value the property is set to can be ignored and that the one that comes from the database should be used. If the DatabaseGeneratedOption
is None
EF will insert the value of the property to the database as the value of the key column.
In Code First - when Code First conventions find an int property that can be the key property for the given entity they by default will configure this column as identity column (meaning the database will generate the value of the key column/property). DatabaseGeneratedOption.None
allows you to overwrite this if you want to set key values on your own.
这篇关于为什么“DatabaseGeneratedOption.None”存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!