private void AddAssociationProperties( string[] propertyNames, IType[] propertyTypes, bool partsOfKey, Func <int, CascadeStyle> getCascadeStyle, EntityType entityType, IReadOnlyCollection <string> superProperties, ModelConfiguration modelConfiguration, EntityMetadata entityMetadata) { for (var i = 0; i < propertyNames.Length; i++) { var propertyType = propertyTypes[i] as IAssociationType; var propertyName = propertyNames[i]; var memberConfiguration = modelConfiguration.GetMember(propertyNames[i]); if (memberConfiguration?.Ignored == true || superProperties?.Contains(propertyName) == true || propertyType == null) { continue; } var navigationProperty = CreateNavigationProperty(propertyType, propertyName, i, partsOfKey, getCascadeStyle, entityType, entityMetadata); if (navigationProperty != null) { entityType.NavigationProperties.Add(navigationProperty); } } }
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 AddIdentifierProperties( AbstractEntityPersister persister, EntityType entityType, ModelConfiguration modelConfiguration, EntityMetadata entityMetadata, BreezeMetadata metadata) { // Add the identifier properties only for the root class if (persister.IsInherited) { return; } if (persister.HasIdentifierProperty) { var memberConfiguration = modelConfiguration.GetMember(persister.IdentifierPropertyName); var dataProperty = CreateDataProperty( persister.IdentifierPropertyName, persister.IdentifierType, true, false, false, memberConfiguration, entityType, persister.Factory); entityType.DataProperties.Insert(0, dataProperty); } else if (persister.IdentifierType is IAbstractComponentType componentType) { modelConfiguration = _breezeConfigurator.GetModelConfiguration(componentType.ReturnedClass); AddDataProperties( componentType.PropertyNames, componentType.Subtypes, componentType.PropertyNullability, null, null, true, entityType, modelConfiguration, metadata, persister.Factory); AddAssociationProperties( componentType.PropertyNames, componentType.Subtypes, true, i => componentType.GetCascadeStyle(i), entityType, null, modelConfiguration, entityMetadata); } }
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 } } }
private void AddDataProperties( string[] propertyNames, IType[] propertyTypes, bool[] propertyNullability, IReadOnlyCollection <string> superProperties, int?versionPropertyIndex, bool partsOfKey, StructuralType structuralType, ModelConfiguration modelConfiguration, BreezeMetadata metadata, ISessionFactoryImplementor sessionFactory) { for (var i = 0; i < propertyNames.Length; i++) { var propertyType = propertyTypes[i]; var propertyName = propertyNames[i]; var memberConfiguration = modelConfiguration.GetMember(propertyNames[i]); if ( memberConfiguration?.Ignored == true || superProperties?.Contains(propertyName) == true || propertyType.IsAssociationType) { continue; } var dataProperty = CreateDataProperty( propertyName, propertyType, partsOfKey, propertyNullability[i], i == versionPropertyIndex, memberConfiguration, structuralType, sessionFactory); if (propertyType is IAbstractComponentType componentType) { AddComplexType( componentType, _breezeConfigurator.GetModelConfiguration(propertyType.ReturnedClass), metadata, partsOfKey, sessionFactory); } if (partsOfKey) { structuralType.DataProperties.Insert(0, dataProperty); } else { structuralType.DataProperties.Add(dataProperty); } // Map enum type if (propertyType is AbstractEnumType nhEnumType && _addedTypes.Add(nhEnumType.ReturnedClass)) { var enumType = nhEnumType.ReturnedClass; metadata.EnumTypes.Add(new EnumType { Namespace = enumType.Namespace, ShortName = enumType.Name, Values = Enum.GetNames(enumType) }); } } }