Programming Entity Framework: Code First

By Julia Lerman, Rowan Miller

Take benefit of the Code First facts modeling strategy in ADO.NET Entity Framework, and the way to construct and configure a version in response to current periods on your enterprise area. With this concise ebook, you’ll paintings hands-on with examples to benefit how Code First can create an in-memory version and database via default, and the way you could exert extra keep watch over over the version via extra configuration.

Code First offers a substitute for the database first and version first methods to the Entity info version. study some great benefits of defining your version with code, no matter if you’re operating with an present database or development one from scratch. when you paintings with visible Studio and comprehend database administration fundamentals, this publication is for you.

  • Learn precisely what Code First does—and does not—enable you to do
  • Understand how estate attributes, relationships, and database mappings are inferred out of your sessions by means of Code First
  • Use info Annotations and the Fluent API to configure the Code First info model
  • Perform complicated suggestions, corresponding to controlling the database schema and overriding the default version caching

This booklet is a continuation of writer Julia Lerman’s Programming Entity Framework, well known because the top booklet at the topic.

Show description

Quick preview of Programming Entity Framework: Code First PDF

Show sample text content

Youtube. com/oreillymedia Acknowledgments designated due to technical reviewers Andrew Peters, from the Entity Framework group, and Suzanne Shushereba, a software program developer at Fletcher Allen healthiness Care in Burlington, Vermont (and a friend). Andrew leveraged his services in Code First to make sure that we hadn’t made any technical gaffes. Suzanne was once new to Code First yet no longer Entity Framework. She not just learn the textual content to show the place shall we offer a greater reason behind a beginner, yet she additionally besides the walkthroughs in visible Studio to aid us locate locations the place delivering extra code will be extra necessary.

Identifier with no a precise Guid worth Neither the database nor Entity Framework is familiar with that we’d like considered one of them to generate a brand new Guid for brand new journeys. without good judgment to generate a brand new Guid for this estate, it inserted the Guid default value—the zeros. if you happen to try and insert one other checklist with an analogous worth in Identifier, the database will throw an mistakes since it expects a special worth. it truly is attainable to configure the database to instantly generate a brand new Guid, by way of surroundings the default price to newid().

You will find the reproduction information in determine 2-4. determine 2-4. reproduction facts from InsertDestination being rerun with no recreating the database Organizing Fluent Configurations when you have loads of configuration to accomplish, the OnModelCreating strategy may perhaps quick develop into beaten with code. you could crew configuration by means of entity variety inside person EntityTypeConfiguration sessions, after which inform the DbModelBuilder approximately them within the OnModelCreating technique. DbModelBuilder has a Configurations estate to that you would be able to upload those EntityTypeConfigurations.

Nation] AS [Country], [Extent2]. [Description] AS [Description], [Extent1]. [Photo] AS [Photo] FROM [dbo]. [LocationPhotos] AS [Extent1] internal subscribe to [dbo]. [Locations] AS [Extent2] ON [Extent1]. [LocationID] = [Extent2]. [LocationID] —RESPONSE TO replace exec sp_executesql N'update [dbo]. [Locations] set [Description] = @0 the place ([LocationID] = @1)', N'@0 nvarchar(500),@1 int', @0='Trust us, you''ll like it! ',@1=1 --RESPONSE TO DELETE exec sp_executesql N'delete [dbo]. [LocationPhotos] the place ([LocationID] = @0)',N'@0 int',@0=1 exec sp_executesql N'delete [dbo].

Configuring a discriminator column to be a boolean Map(m => { m. ToTable("Lodging"); m. Requires("IsResort"). HasValue(false); }) . Map(m => { m. Requires("IsResort"). HasValue(true); }); The ensuing bit column, IsResort, is proven in determine 5-7. determine 5-7. The renamed discriminator column, IsResort Configuring desk in keeping with kind (TPT) Hierarchy whereas TPH includes all the kinds for a hierarchy in one desk, desk in line with style (TPT) purely shops houses from the bottom type in one desk.

Download PDF sample

Rated 4.45 of 5 – based on 4 votes