/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual bool CanSetField([CanBeNull] string fieldName, ConfigurationSource?configurationSource) { if (configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource())) { if (fieldName == null) { return(true); } var fieldInfo = PropertyBase.GetFieldInfo( fieldName, Metadata.DeclaringType, Metadata.Name, shouldThrow: false); return(fieldInfo != null && PropertyBase.IsCompatible( fieldInfo, Metadata.ClrType, Metadata.DeclaringType.ClrType, Metadata.Name, shouldThrow: false)); } return(Metadata.FieldInfo?.GetSimpleMemberName() == fieldName); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual bool HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) { if (Metadata.FieldInfo?.Name == fieldName) { Metadata.SetField(fieldName, configurationSource); return(true); } if (!configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource())) { return(false); } if (fieldName != null) { var fieldInfo = PropertyBase.GetFieldInfo(fieldName, Metadata.DeclaringType.ClrType, Metadata.Name, shouldThrow: configurationSource == ConfigurationSource.Explicit); Metadata.SetFieldInfo(fieldInfo, configurationSource); return(true); } Metadata.SetField(fieldName, configurationSource); return(true); }
private static Func <IUpdateEntry, TProperty> CreateCurrentValueGetter <TProperty>( IPropertyBase propertyBase, bool useStoreGeneratedValues) { var entityClrType = propertyBase.DeclaringType.ClrType; var updateParameter = Expression.Parameter(typeof(IUpdateEntry), "entry"); var entryParameter = Expression.Convert(updateParameter, typeof(InternalEntityEntry)); var shadowIndex = propertyBase.GetShadowIndex(); Expression currentValueExpression; if (shadowIndex >= 0) { currentValueExpression = Expression.Call( entryParameter, InternalEntityEntry.ReadShadowValueMethod.MakeGenericMethod(typeof(TProperty)), Expression.Constant(shadowIndex)); } else { var convertedExpression = Expression.Convert( Expression.Property(entryParameter, "Entity"), entityClrType); var memberInfo = propertyBase.GetMemberInfo(forMaterialization: false, forSet: false); currentValueExpression = PropertyBase.CreateMemberAccess(propertyBase, convertedExpression, memberInfo); if (currentValueExpression.Type != typeof(TProperty)) { currentValueExpression = Expression.Condition( currentValueExpression.MakeHasDefaultValue(propertyBase), Expression.Constant(default(TProperty), typeof(TProperty)), Expression.Convert(currentValueExpression, typeof(TProperty))); } } var storeGeneratedIndex = propertyBase.GetStoreGeneratedIndex(); if (storeGeneratedIndex >= 0) { if (useStoreGeneratedValues) { currentValueExpression = Expression.Condition( Expression.Equal( currentValueExpression, Expression.Constant(default(TProperty), typeof(TProperty))), Expression.Call( entryParameter, InternalEntityEntry.ReadStoreGeneratedValueMethod.MakeGenericMethod(typeof(TProperty)), Expression.Constant(storeGeneratedIndex)), currentValueExpression); } currentValueExpression = Expression.Condition( Expression.Equal( currentValueExpression, Expression.Constant(default(TProperty), typeof(TProperty))), Expression.Call( entryParameter, InternalEntityEntry.ReadTemporaryValueMethod.MakeGenericMethod(typeof(TProperty)), Expression.Constant(storeGeneratedIndex)), currentValueExpression); } return(Expression.Lambda <Func <IUpdateEntry, TProperty> >( currentValueExpression, updateParameter) .Compile()); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public static bool IsIndexerProperty(this PropertyBase propertyBase) => ((IReadOnlyPropertyBase)propertyBase).IsIndexerProperty();
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public static bool IsShadowProperty(this PropertyBase propertyBase) => ((IReadOnlyPropertyBase)propertyBase).IsShadowProperty();