private void AddSyntheticMembers(
            EntityType entityType,
            ModelConfiguration modelConfiguration)
        {
            foreach (var memberConfiguration in modelConfiguration.SyntheticMembers.Values.Where(o => o.Added))
            {
                var dataProperty = CreateDataProperty(
                    memberConfiguration.MemberName,
                    _dataTypeProvider.GetDataType(memberConfiguration.MemberType),
                    false,
                    IsNullable(memberConfiguration.MemberType),
                    false,
                    memberConfiguration,
                    entityType,
                    null);

                dataProperty.IsUnmapped = true;
                entityType.DataProperties.Add(dataProperty);
            }
        }
Пример #2
0
        private ClientModelMetadata Create(Type clientType)
        {
            if (!IsClientModel(clientType))
            {
                return(null);
            }

            var properties          = clientType.GetProperties().ToDictionary(o => o.Name);
            var syntheticProperties = new List <SyntheticForeignKeyProperty>();
            var associations        = new Dictionary <string, Association>();
            var clientProperties    = new List <ClientModelProperty>(properties.Count);

            foreach (var property in clientType.GetProperties())
            {
                var propertyType = property.PropertyType;
                if (property.GetCustomAttribute <ComplexTypeAttribute>() != null)
                {
                    clientProperties.Add(new ClientModelProperty(
                                             property.Name,
                                             propertyType,
                                             true,
                                             null,
                                             true,
                                             false,
                                             false,
                                             false));
                    continue;
                }


                var isCollection          = propertyType.IsGenericType && typeof(IEnumerable).IsAssignableFrom(propertyType);
                var elementType           = isCollection ? propertyType.GetGenericArguments()[0] : propertyType;
                var relatedEntityMetadata = _entityMetadataProvider.IsEntityType(elementType)
                    ? _entityMetadataProvider.GetMetadata(elementType)
                    : null;

                if (relatedEntityMetadata != null || IsClientModel(elementType))
                {
                    clientProperties.Add(
                        isCollection
                        // Add a one to many relation
                            ? CreateCollectionNavigationProperty(
                            clientType,
                            property,
                            elementType,
                            relatedEntityMetadata,
                            associations)
                        // Add a many to one relation
                            : CreateEntityNavigationProperty(
                            clientType,
                            property,
                            properties,
                            relatedEntityMetadata,
                            syntheticProperties,
                            associations)
                        );

                    continue;
                }

                clientProperties.Add(new ClientModelProperty(
                                         property.Name,
                                         propertyType,
                                         false,
                                         _dataTypeProvider.GetDataType(propertyType),
                                         BreezeHelper.IsNullable(propertyType),
                                         property.Name == nameof(IClientModel.Id),
                                         false,
                                         false));
            }

            return(new ClientModelMetadata(
                       clientType,
                       null, // TODO: base type
                       AutoGeneratedKeyType.KeyGenerator,
                       clientProperties,
                       syntheticProperties.ToDictionary(o => o.Name),
                       new List <Type>(),   // TODO: base type
                       new List <string>(), // TODO: base type
                       IdentifierPropertyNames,
                       IdentifierPropertyGetters,
                       IdentifierPropertyTypes,
                       IdentifierPropertyDataTypes,
                       IdentifierPropertyTypeLengths,
                       new HashSet <string>(associations.Values.Where(o => o.IsScalar).SelectMany(o => o.ForeignKeyPropertyNames)),
                       associations
                       ));
        }