Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
|
Convention |
Integer keys: Identity |
|
Data Annotation |
DatabaseGenerated(DatabaseGeneratedOption) |
|
Fluent |
Entity<T>.Property(t=>t.PropertyName) .HasDatabaseGeneratedOption(DatabaseGeneratedOption) |
In the previous section, you learned that by default, Code First
will flag int key properties so that Entity Framework
is aware that the database will generate the values. What about the
Guid key that we just created? Guids require special handling, which involves
the DatabaseGenerated
configuration.
To demonstrate, we’ll add a new method, InsertTrip (Example 3-4) to the console application and call it
from the Main module.