请帮助我在EF7中缺少类EntityTypeConfiguration? 我有这个想法:
public class SmartModelBuilder<T> where T : class {
private ModelBuilder _builder { get; set; }
private Action<EntityTypeBuilder<T>> _entityAction { get; set; }
public SmartModelBuilder(ModelBuilder builder, Action<EntityTypeBuilder<T>> entityAction)
{
this._builder = builder;
this._entityAction = entityAction;
this._builder.Entity<T>(_entityAction);
}
}
我可以像这样通过流畅的api传递配置:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
BlogConfig b = new BlogConfig(builder);
}
public class BlogConfig
{
private ModelBuilder _builder {get; set;}
public BlogConfig(ModelBuilder builder)
{
this._builder = builder;
new SmartModelBuilder<Blog>(_builder, entity => entity.Property(b => b.Url).Required());
}
}
或者在BlogConfig中检查创建静态元数据并在OnModelCreating中运行此元数据。 我没有经过测试..