How do I remove underscore of foreign key fields in code first by convention

前端 未结 7 952
傲寒
傲寒 2020-11-30 01:20

I\'ve got multiple classes (including TPT) in my project. Each POCO has a BaseClass, which has a GUID (called GlobalKey) as primary ke

7条回答
  •  悲哀的现实
    2020-11-30 01:30

    I found that key column customizations were not being caught by the ForeignKeyNamingConvention. Made this change to catch them.

    private bool DoPropertiesHaveDefaultNames(ReadOnlyMetadataCollection properties, string roleName, ReadOnlyMetadataCollection otherEndProperties)
    {
        if (properties.Count == otherEndProperties.Count)
        {
            for (int i = 0; i < properties.Count; ++i)
            {
                if (properties[i].Name.EndsWith("_" + otherEndProperties[i].Name))
                {
                    return true;
                }
                else
                {
                    var preferredNameProperty =
                        otherEndProperties[i]
                            .MetadataProperties
                            .SingleOrDefault(x => x.Name.Equals("PreferredName"));
    
                    if (null != preferredNameProperty)
                    {
                        if (properties[i].Name.EndsWith("_" + preferredNameProperty.Value))
                        {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
    

提交回复
热议问题