private FieldInfo GetFieldToSet(IConventionPropertyBase propertyBase)
        {
            if (propertyBase == null ||
                !ConfigurationSource.Convention.Overrides(propertyBase.GetFieldInfoConfigurationSource()))
            {
                return(null);
            }

            var type = propertyBase.DeclaringType.ClrType;

            while (type != null)
            {
                var fieldInfo = TryMatchFieldName(
                    propertyBase.DeclaringType.Model, type, propertyBase.ClrType, propertyBase.Name);
                if (fieldInfo != null &&
                    (propertyBase.PropertyInfo != null || propertyBase.Name == fieldInfo.GetSimpleMemberName()))
                {
                    return(fieldInfo);
                }

                type = type.GetTypeInfo().BaseType;
            }

            return(null);
        }
Ejemplo n.º 2
0
        private FieldInfo GetFieldToSet(IConventionPropertyBase propertyBase)
        {
            if (propertyBase == null ||
                !ConfigurationSource.Convention.Overrides(propertyBase.GetFieldInfoConfigurationSource()) ||
                propertyBase.IsIndexerProperty() ||
                propertyBase.IsShadowProperty())
            {
                return(null);
            }

            var entityType = (IConventionEntityType)propertyBase.DeclaringType;
            var type       = entityType.ClrType;
            var baseTypes  = entityType.GetAllBaseTypes().ToArray();

            while (type != null)
            {
                var fieldInfo = TryMatchFieldName(propertyBase, entityType, type);
                if (fieldInfo != null &&
                    (propertyBase.PropertyInfo != null || propertyBase.Name == fieldInfo.GetSimpleMemberName()))
                {
                    return(fieldInfo);
                }

                type       = type.BaseType;
                entityType = baseTypes.FirstOrDefault(et => et.ClrType == type);
            }

            return(null);
        }