Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

fluent api

public class OfficeContext: DbContext 
{

   
  	public virtual DbSet<Course> Courses { get; set; }
    public virtual DbSet<Enrollment> Enrollments { get; set; }
    public virtual DbSet<Student> Students { get; set; }
  	public virtual DbSet<Worker> Workers { get; set; }
        
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
         //Write Fluent API configurations here
      	 //some example of fluent api
      	 //Configure default schema
         modelBuilder.HasDefaultSchema("Admin");

         //Map entity to table
         modelBuilder.Entity<Student>().ToTable("StudentsInfo");
         modelBuilder.Entity<Course>().ToTable("CoursesInfo");
         modelBuilder.Entity<Enrollment>().ToTable("EnrollmentsInfo");
      	 modelBuilder.Entity<Enrollment>().ToTable("WorkersInfo");

    }
}
 
PREVIOUS NEXT
Tagged: #fluent #api
ADD COMMENT
Topic
Name
2+6 =