Пожалуйста, дайте мне знать, в чем суть концепции, лежащие в основе обоих этих подходов, и что должно следовать?
Подход 1: Использование EntityTypeConfiguration
Код: Выделить всё
public class BlogsMap : EntityTypeConfiguration
{
public BlogsMap(string schema)
{
ToTable("BLOG");
HasKey(t => t.BlogId);
Property(t => t.BlogId).HasColumnName("BLOGID");
Property(t => t.Name).HasColumnName("NAME");
Property(t => t.Url).HasColumnName("URL");
}
}
public class BlogContext : DbContext
{
public BlogContext(string name)
: base(name)
{
}
public IDbSet BLOG { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new BlogMap(string.Empty));
}
}
Код: Выделить всё
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public virtual List
Posts { get; set; }
}
public class BloggingContext : DbContext
{
public DbSet Blogs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity();
}
}
Подробнее здесь: https://stackoverflow.com/questions/277 ... elcreating