Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

3. Using Conventions and Configurations ... > Configuring Database-Generated Prope...

Configuring Database-Generated Properties

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.

Example 3-4. The InsertTrip method

private static 

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial