public EntityTypeMetadata(EntityType dbMetadata, EntityTypeMetadata baseEntityType)
 {
     EntityTypeId        = dbMetadata.Id;
     Name                = dbMetadata.Name;
     SchemaName          = dbMetadata.SchemaName;
     SingularTitle       = (dbMetadata.SingularTitle) ?? (dbMetadata.Name.SmartSeparate());
     TableName           = dbMetadata.TableName;
     DisplayNameProperty = dbMetadata.DisplayNamePath;
     CodeProperty        = dbMetadata.CodePath;
     BaseEntityType      = baseEntityType;
 }
Beispiel #2
0
 protected override TData GetDefaultValue(EntityTypeMetadata owner)
 {
     if (_defaultValues != null && _defaultValues.TryGetValue(owner.GeneralBehavior, out TData data))
     {
         return(data);
     }
     if (_defaultValueGenerator != null)
     {
         return(_defaultValueGenerator(owner));
     }
     return(base.GetDefaultValue(owner));
 }
Beispiel #3
0
 public PropertyMetadata(IMetadataCache cache, string name, EntityTypeMetadata owner, PropertyGeneralUsageCategoryStruct generalBehavior
                         , DataType dataType, bool isNullable, bool isExpression, string title, string expressionDefinitionIdentifier, IEnumerable <MetadataDbAccess.Entities.PropertyBehavior> behaviors)
 {
     _cache         = cache;
     Name           = name;
     Title          = title;
     GeneralBahvior = generalBehavior;
     _dataTypeInfo  = dataType;
     DataType       = (DataTypes)dataType.Id;
     IsNullable     = isNullable;
     IsExpression   = isExpression;
     _expressionDefinitionIdentifier = expressionDefinitionIdentifier;
     owner.AddProperty(this);
     Owner     = owner;
     Behaviors = behaviors?.Select(x => new PropertyBehaviorMetadata
     {
         AdditionalBehavior = new AdditionalBehaviorMetadata
         {
             Name       = x.AdditionalBehavior.Name,
             Definition = x.AdditionalBehavior.Definition
         },
         Parameters = x.Parameters
     }).ToList();
 }
Beispiel #4
0
        public MetadataCache(MetadataBundle bundle)
        {
            _dataTypesByIndetifier = bundle.DataTypes.ToDictionary(x => x.Identifier);
            LoadEntityGeneralUsageCategories(bundle);
            LoadPropertyGeneralUsageCategories(bundle);

            if (!_facetsDefined)
            {
                _facetsDefined = true;
                EntityTypeMetadata.DefineFacets(bundle.EntityTypeFacetDefinitions);
                PropertyMetadata.DefineFacets(bundle.PropertyFacetDefinitions);

                foreach (var defaultValue in bundle.PropertyFacetDefaultValues)
                {
                    (PropertyMetadata._facets[defaultValue.FacetDefinitionId] as IMetadataFacet <PropertyGeneralUsageCategoryStruct>)
                    .AddDefaultValue(GetPropertyGeneralUsageCategory(defaultValue.GeneralUsageCategoryId), defaultValue.DefaultValue);
                }

                foreach (var defaultValue in bundle.EntityTypeFacetDefaultValues)
                {
                    (EntityTypeMetadata._facets[defaultValue.GeneralUsageCategoryId] as IMetadataFacet <EntityGeneralUsageCategoryStruct>)
                    .AddDefaultValue(GetEntityGeneralUsageCategory(defaultValue.GeneralUsageCategoryId), defaultValue.DefaultValue);
                }
            }

            var map = new Dictionary <int, PropertyMetadata>();

            foreach (var dbEntityMetadata in bundle.EntityTypes)
            {
                var entityTypeMetadata = new EntityTypeMetadata(dbEntityMetadata, null);
                foreach (var dbPropertyMetadata in dbEntityMetadata.Properties ?? Enumerable.Empty <Property>())
                {
                    var propertyMetadata = new PropertyMetadata(this, dbPropertyMetadata.Name, entityTypeMetadata, new PropertyGeneralUsageCategoryStruct
                    {
                        PropertyGeneralUsageCategoryId = dbPropertyMetadata.GeneralUsageCategoryId,
                        Name = dbPropertyMetadata.GeneralUsageCategory.Name
                    }, dbPropertyMetadata.DataType, dbPropertyMetadata.IsNullable, dbPropertyMetadata.IsExpression, dbPropertyMetadata.Title,
                                                                dbPropertyMetadata.ExpressionDefinition?.Identifier, dbPropertyMetadata.PropertyBehaviors)
                    {
                        EntityTypeName = dbPropertyMetadata.DataEntityType?.Name
                    };
                    map.Add(dbPropertyMetadata.Id, propertyMetadata);

                    if (dbPropertyMetadata.PropertyFacetValues != null)
                    {
                        foreach (var facetValue in dbPropertyMetadata.PropertyFacetValues)
                        {
                            dynamic facet = PropertyMetadata._facets[facetValue.FacetDefinitionId];
                            propertyMetadata.SetValue(facet, facetValue.Value);
                        }
                    }
                }

                if (dbEntityMetadata.FacetValues != null)
                {
                    foreach (var facetValue in dbEntityMetadata.FacetValues)
                    {
                        dynamic facet = EntityTypeMetadata._facets[facetValue.FacetDefinitionId];
                        entityTypeMetadata.SetValue(facet, facetValue.Value);
                    }
                }

                _entityTypesByName.Add(dbEntityMetadata.Name, entityTypeMetadata);
                _entityTypesById.Add(dbEntityMetadata.Id, entityTypeMetadata);
            }

            foreach (var property in bundle.EntityTypes.Where(x => x.Properties != null).SelectMany(x => x.Properties))
            {
                if (property.ForeignKeyPropertyId.HasValue)
                {
                    map[property.Id].ForeignKey = map[property.ForeignKeyPropertyId.Value];
                }
                if (property.InversePropertyId.HasValue)
                {
                    map[property.Id].InverseProperty = map[property.InversePropertyId.Value];
                }
            }

            foreach (var entityType in bundle.EntityTypes.Where(x => x.BaseEntityTypeId.HasValue))
            {
                _entityTypesByName[entityType.Name].BaseEntityType = _entityTypesByName[entityType.BaseEntityType.Name];
            }

            _expressions = new Dictionary <string, ExpressionInfo>();
            foreach (var expressionDefiniction in bundle.ExpressionDefinitions)
            {
                _expressions.Add(expressionDefiniction.Identifier, new ExpressionInfo
                {
                    MainInputEntityTypeName = expressionDefiniction.MainInputEntityType.Name
                });
            }

            foreach (var body in bundle.ExpressionBodies)
            {
                if (!_expressions.TryGetValue(body.Definition.Identifier, out var info))
                {
                    continue;
                }
                info.Format = body.FormatId;
                info.Body   = body.Body;
            }
        }