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.
Its effect is to configure EF to not fetch a new identity value after inserting into the database.
来源:https://stackoverflow.com/questions/15567886/why-does-the-databasegeneratedoption-none-exist