Synopses & Reviews
This mini book will act as an extension to Programming Entity Framework 2nd Edition. Code First is an additional means of building a model to be used with the Entity Framework and is creating a lot of excitement in the .NET development community. The reader will begin with an overview of what Code First is, why it was created, how it fits into the Entity Framework and when to use it over the alternatives. Next the reader will gain an understanding of how Code First's built in conventions work and how to override them with configuration — whether they choose to use attribute based Data Annotations or strongly typed Fluent API configurations. The mini-book will then review the modeling possibilities of Code First, looking first at the impact of its conventions and then demonstrating how to override that behavior (and its impact on the database) first with the Annotations and then with the Fluent API. The book will also explore how Code First Database initialization works, the options it provides and how they impact your application development and database. Finally the reader will get a chance to see Code First in action in a small application. Because more complex application development with Code First will depend on an understanding of the DbContext API, which is the focus of Minibook #2, readers will see additional application scenarios with Code First in that following mini-book.
Take advantage of the Code First data modeling approach in ADO.NET Entity Framework, and learn how to build and configure a model based on existing classes in your business domain. With this concise book, youll work hands-on with examples to learn how Code First can create an in-memory model and database by default, and how you can exert more control over the model through further configuration.
Code First provides an alternative to the database first and model first approaches to the Entity Data Model. Learn the benefits of defining your model with code, whether youre working with an existing database or building one from scratch. If you work with Visual Studio and understand database management basics, this book is for you.
- Learn exactly what Code First does—and does not—enable you to do
- Understand how property attributes, relationships, and database mappings are inferred from your classes by Code First
- Use Data Annotations and the Fluent API to configure the Code First data model
- Perform advanced techniques, such as controlling the database schema and overriding the default model caching
This book is a continuation of author Julia Lermans Programming Entity Framework, widely recognized as the leading book on the topic.
About the Author
Julia Lerman is the leading independent authority on the Entity Framework and has been using and teaching the technology since its inception in 2006. She is well known in the .NET community as a Microsoft MVP, ASPInsider, and INETA Speaker. Julia is a frequent presenter at technical conferences around the world and writes articles for many well-known technical publications including the Data Points column in MSDN Magazine.
Julia lives in Vermont with her husband, Rich, and gigantic dog, Sampson, where she runs the Vermont.NET User Group. You can read her blog at www.thedatafarm.com/blog and follow her on Twitter at julielerman.
Rowan Miller is based in Seattle, Washington and works as a Program Manager for the ADO.Net Entity Framework team at Microsoft. Prior to moving to the US he resided in the small state of Tasmania in Australia. Rowan speaks at technical conferences and blogs at http://romiller.com. Outside of technology Rowan's passions include snowboarding, mountain biking, horse riding, rock climbing and pretty much anything else that involves being active. The primary focus of his life, however, is to follow Jesus.
Table of Contents
Preface; Audience; Contents of This Book; Conventions Used in This Book; Using Code Examples; Safari® Books Online; How to Contact Us; Acknowledgments; Chapter 1: Welcome to Code First; 1.1 Modeling with EF Before Code First; 1.2 Inception of Code First; 1.3 Getting Code First to Developers in Between .NET Releases; 1.4 Writing the Code...First; 1.5 Managing Objects with DbContext; 1.6 Using the Data Layer and Domain Classes; 1.7 Getting from Classes to a Database; 1.8 Working with Configuration; 1.9 Creating or Pointing to a Database; 1.10 What Code First Does Not Support; 1.11 Learning from This Book; Chapter 2: Your First Look at Code First; 2.1 Introducing EF to the Domain Classes; 2.2 Putting the Pieces Together in an Example; 2.3 Overriding Convention with Configurations; 2.4 Understanding How Model Changes Impact Database Initialization; 2.5 Configuring Code First with the Fluent API; 2.6 Summary; Chapter 3: Using Conventions and Configurations for Property Attributes; 3.1 Working with Property Attributes in Code First; 3.2 Mapping Keys; 3.3 Configuring Database-Generated Properties; 3.4 Configuring TimeStamp/RowVersion Fields for Optimistic Concurrency; 3.5 Configuring Non-Timestamp Fields for Concurrency; 3.6 Mapping to Non-Unicode Database Types; 3.7 Affecting the Precision and Scale of Decimals; 3.8 Working with Complex Types in Code First; 3.9 Configuring Properties of Complex Types; 3.10 Summary; Chapter 4: Using Convention and Configuration for Relationships; 4.1 Working with Multiplicity; 4.2 Working with Foreign Keys; 4.3 Working with Inverse Navigation Properties; 4.4 Working with Cascade Delete; 4.5 Exploring Many-to-Many Relationships; 4.6 Working with Relationships that Have Unidirectional Navigation; 4.7 Working with One-to-One Relationships; 4.8 Summary; Chapter 5: Using Conventions and Configurations for Database Mappings; 5.1 Mapping Class Name to Database Table and Schema Name; 5.2 Mapping Property Names to Database Columns; 5.3 Allowing Multiple Entities to Map to a Single Table: aka Table Splitting; 5.4 Mapping a Single Entity Across Multiple Tables; 5.5 Controlling Which Types Get Mapped to the Database; 5.6 Understanding Property Mapping and Accessibility; 5.7 Preventing Properties from Being Included in the Model; 5.8 Mapping Inheritance Hierarchies; 5.9 Working with Abstract Base Classes; 5.10 Mapping Relationships; 5.11 Summary; Chapter 6: Controlling Database Location, Creation Process, and Seed Data; 6.1 Controlling the Database Location; 6.2 Working with Database Initialization; 6.3 Using Database Initializers to Seed Data; 6.4 Using Database Initialization to Further Affect Database Schema; 6.5 Summary; Chapter 7: Advanced Concepts; 7.1 Mapping to Nontable Database Objects; 7.2 Removing Conventions; 7.3 Taking Control of Model Caching; 7.4 Working with the EdmMetadata Table; 7.5 Using Code First with ObjectContext; 7.6 Summary; Chapter 8: What's Coming Next for Code First; 8.1 Code First Migrations; 8.2 Entity Framework Power Tools;