Chapter 3. Using Conventions and Configurations for Property Attributes
In Chapter 2, you got your first look at some of Code First’s conventions and how to override Code First’s default behavior with configuration. You not only saw how to configure with Data Annotations, but we also applied the same configuration using the Fluent API so you could see a direct comparison.
In this and the next few chapters, we’ll walk you through a variety of areas where you can configure your model. For each topic you’ll see what Code First does by convention and then you’ll learn how to override the convention with Data Annotations and the Fluent API. As you’ve learned, there are a number of configurations you can apply using the Fluent API that are not available with Data Annotations. We’ll be sure to point out those cases when it’s time to dig into them.
We’ll kick things off in this chapter by focusing on Code First conventions and configuration that affect attributes of the properties and their related database columns. You’ll learn about working with attributes such as the length of a string or byte array and precision of numeric values. You’ll work with key properties and properties that are involved with optimistic concurrency. Finally, you’ll learn about how Code First detects when a property is in fact a complex type (aka value type), as well as how to help when it’s unable to infer these complex types from your domain classes.
Working with Property Attributes in Code First
In Chapter 2, you ...
Get Programming Entity Framework: Code First now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.