The following just specify contraints on size, key, etc.
It's done automatically if you the fieldname is called Id or TheEntitityId, but if you can't use that field name:
modelBuilder.Entity<Manager>() .HasKey(ma => ma.ManagerCode);
Use an anonymous object:
modelBuilder.Entity<Department>()
.HasKey(t => new { t.DepartmentID, t.Name });
modelBuilder.Entity<Manager>().Property(ma => ma.Name) .HasMaxLength(20);
modelBuilder.Entity<Department>().Property(dp => dp.Name) .IsRequired();
You can ignore calculated columns:
modelBuilder.Entity<Department>().Ignore(t => t.Budget);
modelBuilder.Entity<Department>().Property(t => t.Name)
.HasColumnName("DepartmentName");
virtual to enable improved Change Tracking (by going from Snapshot CT to Proxy POCO Change Tracking, which is based on IPOCO/IEntityWithChangeTracker).virtual to enable lazy loading.ICollection<Entities>private set for Id, etc:public string Id {get; private set;}[Ignore] (see IT:AD:Code First:DataAnnotations).DataContext.OnModelCreating(): modelBuilder.Entity<Department>().Ignore(t => t.Budget); (see IT:AD:Code First:FluentAPI:Properties)public FullName {get {return _first + " " + _last;} set {}}DataContext.OnModelCreating(): modelBuilder.Entity<Dept>().Property(t => t.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); (see IT:AD:Code First:FluentAPI:Properties)