# IT:AD:Code First:Entities:Classes # * [[../|(UP)]] {{indexmenu>.#2|nsort tsort}} ### CheckList: Classes Design ### * MUST: Parameter less constructor * MUST: Not be sealed or abstract * MUST: Have a PK. * Convention: Named `Id` or `Id` * DataAnnotation: `[Key()]` (see [[IT/AD/Code First/Annotations/]]) * FluentAPI: `modelBuilder.Entity().HasKey(ma => ma.SSN);`(see [[IT/AD/Code First/FluentAPI/Properties/]]) * COULD:Table Name mapping can be forced by: * DataAnnotation: `[ClassName]` (see [[IT/AD/EF/Annotations/]]): * FluentAPI: within `DataContext.OnModelCreating()`: `modelBuilder.Entity().Property(i => i.Name) .HasColumnName("ClientInvoices");` (see [[IT/AD/Code First/FluentAPI/]]): * Note: For more complex mapping: [http://bit.ly/tjUwK8](http://bit.ly/tjUwK8) * CONSIDER: You can exclude entities: * DataAnnotation: `[NotMapped]` (see [[IT/AD/Code First/DataAnnotations/]]) * FluentAPI: within `DataContext.OnModelCreating()`: `modelBuilder.Ignore()` (see [[IT/AD/Code First/FluentAPI/]]) Example: `modelBuilder.Entity.MapSingleType().ToTable("xyxTable");` * CONSIDER: Watch out for design flaw of making Entitities into *Anemic Entities* * Consider using Partial or Extension Methods to contain Domain Logic in Entities rather than forcing it to be included in the Application Layer outsider of the Domain Layer. * `_graphContext.Configuration.AutoDetectChangesEnabled = false;`