# IT:AD:Code First:FluentAPI:Properties # * [[../|(UP)]] {{indexmenu>.#2|nsort tsort}} ## Examples: Properties ## The following just specify contraints on size, key, etc. For Relationship Contraints, see [[IT/AD/Code First/FluentAPI/Relationships/]] #### Primary Key #### It's done automatically if you the fieldname is called `Id` or `TheEntitityId`, but if you can't use that field name: modelBuilder.Entity() .HasKey(ma => ma.ManagerCode); #### Composite Keys #### Use an anonymous object: modelBuilder.Entity() .HasKey(t => new { t.DepartmentID, t.Name }); #### MaxLength #### modelBuilder.Entity().Property(ma => ma.Name) .HasMaxLength(20); #### Required #### modelBuilder.Entity().Property(dp => dp.Name) .IsRequired(); #### Ignore #### You can ignore calculated columns: modelBuilder.Entity().Ignore(t => t.Budget); #### Mapping to a different Column #### modelBuilder.Entity().Property(t => t.Name) .HasColumnName("DepartmentName"); #### Reference: Property Related FluentAPI #### * [http://msdn.microsoft.com/en-us/library/hh295847(v=vs.103).aspx](http://msdn.microsoft.com/en-us/library/hh295847(v=vs.103).aspx)