数据库第一环境中的可插入约定

时间:2014-07-15 00:53:17

标签: entity-framework

使用实体框架6+,我们现在可以像这样向模型构建器添加自定义约定。

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Add(FilterConvention.Create<ITenantOwned, Guid>("TenantOwned", (e, tenantKey) => e.TenantKey == tenantKey));
    modelBuilder.Conventions.Add(FilterConvention.Create<ISoftDelete>("SoftDeleted", e => e.Deleted == false));
    base.OnModelCreating(modelBuilder);
}       

但是我无法让它工作,因为我们所有的项目都有一个EDMX文件。当您允许通过高飞连接字符串读入元数据时,OnModelCreating永远不会被调用。我很好,OnModelCreating永远不会被调用,除了我可以告诉我无法在任何其他时间访问modelBuilder,以便将我自己的约定注入到模型中。

实际情况是,非代码第一用户无法使用约定,或者我忽略了某些内容。

0 个答案:

没有答案
相关问题