Tutorial by Examples

EntityFramewok Fluent API is a powerful and elegant way of mapping your code-first domain models to underlying database. This also can be used with code-first with existing database. You have two options when using Fluent API: you can directly map your models on OnModelCreating method or you can cre...
By using the .HasKey() method, a property can be explicitly configured as primary key of the entity. using System.Data.Entity; // .. public class PersonContext : DbContext { // .. protected override void OnModelCreating(DbModelBuilder modelBuilder) { // .. ...
By using the .HasKey() method, a set of properties can be explicitly configured as the composite primary key of the entity. using System.Data.Entity; // .. public class PersonContext : DbContext { // .. protected override void OnModelCreating(DbModelBuilder modelBuilder) {...
By using the .HasMaxLength() method, the maximum character count can be configured for a property. using System.Data.Entity; // .. public class PersonContext : DbContext { // .. protected override void OnModelCreating(DbModelBuilder modelBuilder) { // .. ...
By using the .IsRequired() method, properties can be specified as mandatory, which means that the column will have a NOT NULL constraint. using System.Data.Entity; // .. public class PersonContext : DbContext { // .. protected override void OnModelCreating(DbModelBuilder modelB...
When a navigation property exist on a model, Entity Framework will automatically create a Foreign Key column. If a specific Foreign Key name is desired but is not contained as a property in the model, it can be set explicitly using the Fluent API. By utilizing the Map method while establishing the F...

Page 1 of 1