private void AddSyntheticForeignKeyProperties( ModelMetadata modelMetadata, EntityType entityType, ModelConfiguration modelConfiguration) { foreach (var syntheticProperty in modelMetadata.SyntheticForeignKeyProperties.Values.Where(o => !o.Derived)) { var memberConfiguration = modelConfiguration.GetSyntheticMember(syntheticProperty.Name); var associationConfiguration = modelConfiguration.GetMember(syntheticProperty.AssociationPropertyName); if (memberConfiguration?.Ignored == true || associationConfiguration?.Ignored == true && memberConfiguration?.Ignored == null) { continue; } var dataProperty = CreateDataProperty( syntheticProperty.Name, syntheticProperty.IdentifierDataType, syntheticProperty.IsPartOfKey, associationConfiguration?.IsNullable ?? syntheticProperty.IsNullable, false, memberConfiguration, entityType, associationConfiguration?.MaxLength ?? syntheticProperty.IdentifierLength); dataProperty.IsUnmapped = true; entityType.DataProperties.Add(dataProperty); } }
private void ApplyModelConfiguration( Type type, JsonPropertyCollection properties, ModelConfiguration modelConfiguration, ModelMetadata metadata, Dictionary <JsonProperty, MemberInfo> propertyMembers) { foreach (var property in properties) { var memberConfiguration = modelConfiguration.GetMember(property.UnderlyingName); if (memberConfiguration != null) { ConfigureProperty(property, memberConfiguration); } var isMappedProperty = metadata?.AllProperties.Contains(property.UnderlyingName); var syntheticConfiguration = modelConfiguration.GetSyntheticMember(property.UnderlyingName); if (syntheticConfiguration == null && isMappedProperty == false && memberConfiguration?.Serialize != true && memberConfiguration?.Deserialize != true) { // Do not serialize a non mapped entity property by default (we do not want to expose data that the client will not use) property.Ignored = memberConfiguration?.Ignored ?? true; } if (syntheticConfiguration?.SerializeFunction != null || memberConfiguration?.SerializeFunction != null || propertyMembers.TryGetValue(property, out var member) && member.IsProperty() && !member.IsAutoProperty(true)) { // Throw when a non auto or synthetic property lazy loads an uninitialized association (e.g. CustomerId => Organization.Customer.Id) property.ValueProvider = CreateLazyLoadGuard(property.ValueProvider, type, property.UnderlyingName); } if (isMappedProperty == true) { property.Writable = memberConfiguration?.Deserialize ?? true; // Non public mapped property setter shall be writable by default } } }