实体框架6 RTM - 自定义关系约定

时间:2014-01-31 17:25:24

标签: entity-framework entity-framework-6 convention

我在EF6的测试版中使用了this这样的约定:

public class NavigationPropertyConfigurationConvention : IConfigurationConvention<PropertyInfo, NavigationPropertyConfiguration>
{
    public void Apply(PropertyInfo propertyInfo, Func<NavigationPropertyConfiguration> configuration)
    {
        var foreignKeyProperty = propertyInfo.DeclaringType.GetProperty("Id" + propertyInfo.Name);

        if (foreignKeyProperty != null && configuration().Constraint == null)
        {
            var fkConstraint = new ForeignKeyConstraintConfiguration();
            fkConstraint.AddColumn(foreignKeyProperty);

            configuration().Constraint = fkConstraint;
        }           
    }
}

但是由于IConfigurationConvention接口已被标记为内部,我无法升级我的EF的引用。已经在很多地方搜索过,但没有找到如何在RTM版本中重现该功能。

我也试过this,但似乎只适用于独立关联(IAs),因为我在CLR对象中有FK,所以不是我的情况。

有人再做过吗?

谢谢!

0 个答案:

没有答案
相关问题