Esempio n. 1
0
        public static EdmProperty Clone(this EdmProperty tableColumn)
        {
            DebugCheck.NotNull(tableColumn);

            var columnMetadata
                = new EdmProperty(tableColumn.Name, tableColumn.TypeUsage)
                {
                Nullable = tableColumn.Nullable,
                StoreGeneratedPattern = tableColumn.StoreGeneratedPattern,
                IsFixedLength         = tableColumn.IsFixedLength,
                IsMaxLength           = tableColumn.IsMaxLength,
                IsUnicode             = tableColumn.IsUnicode,
                MaxLength             = tableColumn.MaxLength,
                Precision             = tableColumn.Precision,
                Scale = tableColumn.Scale
                };

            tableColumn.Annotations.Each(a => columnMetadata.GetMetadataProperties().Add(a));

            return(columnMetadata);
        }
Esempio n. 2
0
 public virtual void Apply(EdmModel item, DbModel model)
 {
   Check.NotNull<EdmModel>(item, nameof (item));
   Check.NotNull<DbModel>(model, nameof (model));
   foreach (var data in item.EntityTypes.Where<EntityType>((Func<EntityType, bool>) (entityType =>
   {
     if (entityType.KeyProperties.Count == 0)
       return entityType.BaseType == null;
     return false;
   })).Select(entityType => new
   {
     entityType = entityType,
     entityTypeConfiguration = entityType.GetConfiguration() as EntityTypeConfiguration
   }).Where(_param0 =>
   {
     if (_param0.entityTypeConfiguration == null || !_param0.entityTypeConfiguration.IsExplicitEntity && _param0.entityTypeConfiguration.IsStructuralConfigurationOnly)
       return !_param0.entityType.Members.Where<EdmMember>(new Func<EdmMember, bool>(Helper.IsNavigationProperty)).Any<EdmMember>();
     return false;
   }).Select(_param1 => new
   {
     \u003C\u003Eh__TransparentIdentifier0 = _param1,
     matchingAssociations = item.AssociationTypes.Where<AssociationType>((Func<AssociationType, bool>) (associationType =>
     {
       if (associationType.SourceEnd.GetEntityType() != _param1.entityType)
         return associationType.TargetEnd.GetEntityType() == _param1.entityType;
       return true;
     })).Select(associationType => new
     {
       associationType = associationType,
       declaringEnd = associationType.SourceEnd.GetEntityType() == _param1.entityType ? associationType.SourceEnd : associationType.TargetEnd
     }).Select(_param0 => new
     {
       \u003C\u003Eh__TransparentIdentifier2 = _param0,
       declaringEntity = _param0.associationType.GetOtherEnd(_param0.declaringEnd).GetEntityType()
     }).Select(_param1 => new
     {
       \u003C\u003Eh__TransparentIdentifier3 = _param1,
       navigationProperties = _param1.declaringEntity.Members.Where<EdmMember>(new Func<EdmMember, bool>(Helper.IsNavigationProperty)).Cast<NavigationProperty>().Where<NavigationProperty>((Func<NavigationProperty, bool>) (n => n.ResultEnd.GetEntityType() == _param1.entityType))
     }).Select(_param0 => new
     {
       DeclaringEnd = _param0.\u003C\u003Eh__TransparentIdentifier3.\u003C\u003Eh__TransparentIdentifier2.declaringEnd,
       AssociationType = _param0.\u003C\u003Eh__TransparentIdentifier3.\u003C\u003Eh__TransparentIdentifier2.associationType,
       DeclaringEntityType = _param0.\u003C\u003Eh__TransparentIdentifier3.declaringEntity,
       NavigationProperties = _param0.navigationProperties.ToList<NavigationProperty>()
     })
   }).Where(_param0 => _param0.matchingAssociations.All(a =>
   {
     if (a.AssociationType.Constraint == null && a.AssociationType.GetConfiguration() == null && (!a.AssociationType.IsSelfReferencing() && a.DeclaringEnd.IsOptional()))
       return a.NavigationProperties.All<NavigationProperty>((Func<NavigationProperty, bool>) (n => n.GetConfiguration() == null));
     return false;
   })).Select(_param0 => new
   {
     EntityType = _param0.\u003C\u003Eh__TransparentIdentifier0.entityType,
     MatchingAssociations = _param0.matchingAssociations.ToList()
   }).ToList())
   {
     ComplexType complexType = item.AddComplexType(data.EntityType.Name, data.EntityType.NamespaceName);
     foreach (EdmProperty declaredProperty in data.EntityType.DeclaredProperties)
       complexType.AddMember((EdmMember) declaredProperty);
     foreach (MetadataProperty annotation in data.EntityType.Annotations)
       complexType.GetMetadataProperties().Add(annotation);
     foreach (var matchingAssociation in data.MatchingAssociations)
     {
       foreach (NavigationProperty navigationProperty in matchingAssociation.NavigationProperties)
       {
         if (matchingAssociation.DeclaringEntityType.Members.Where<EdmMember>(new Func<EdmMember, bool>(Helper.IsNavigationProperty)).Contains<EdmMember>((EdmMember) navigationProperty))
         {
           matchingAssociation.DeclaringEntityType.RemoveMember((EdmMember) navigationProperty);
           EdmProperty edmProperty = matchingAssociation.DeclaringEntityType.AddComplexProperty(navigationProperty.Name, complexType);
           foreach (MetadataProperty annotation in navigationProperty.Annotations)
             edmProperty.GetMetadataProperties().Add(annotation);
         }
       }
       item.RemoveAssociationType(matchingAssociation.AssociationType);
     }
     item.RemoveEntityType(data.EntityType);
   }
 }
Esempio n. 3
0
        private EdmProperty MapPrimitiveOrComplexOrEnumProperty(
            PropertyInfo propertyInfo,
            Func <StructuralTypeConfiguration> structuralTypeConfiguration,
            bool discoverComplexTypes = false)
        {
            EdmProperty property = propertyInfo.AsEdmPrimitiveProperty();

            if (property == null)
            {
                Type        underlyingType = propertyInfo.PropertyType;
                ComplexType complexType    = this._typeMapper.MapComplexType(underlyingType, discoverComplexTypes);
                if (complexType != null)
                {
                    property = EdmProperty.CreateComplex(propertyInfo.Name, complexType);
                }
                else
                {
                    bool flag = underlyingType.TryUnwrapNullableType(out underlyingType);
                    if (underlyingType.IsEnum())
                    {
                        EnumType enumType = this._typeMapper.MapEnumType(underlyingType);
                        if (enumType != null)
                        {
                            property          = EdmProperty.CreateEnum(propertyInfo.Name, enumType);
                            property.Nullable = flag;
                        }
                    }
                }
            }
            if (property != null)
            {
                property.SetClrPropertyInfo(propertyInfo);
                new AttributeMapper(this._typeMapper.MappingContext.AttributeProvider).Map(propertyInfo, (ICollection <MetadataProperty>)property.GetMetadataProperties());
                if (!property.IsComplexType)
                {
                    this._typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(propertyInfo, (Func <PropertyConfiguration>)(() => (PropertyConfiguration)structuralTypeConfiguration().Property(new PropertyPath(propertyInfo), new OverridableConfigurationParts?())), this._typeMapper.MappingContext.ModelConfiguration);
                }
            }
            return(property);
        }
Esempio n. 4
0
        public static void SetUnpreferredUniqueName(this EdmProperty tableColumn, string name)
        {
            DebugCheck.NotNull(tableColumn);

            tableColumn.GetMetadataProperties().SetAnnotation(UnpreferredUniqueNameAnnotation, name);
        }
Esempio n. 5
0
        public static void SetOrder(this EdmProperty tableColumn, int order)
        {
            DebugCheck.NotNull(tableColumn);

            tableColumn.GetMetadataProperties().SetAnnotation(OrderAnnotation, order);
        }
Esempio n. 6
0
        public static void SetConfiguration(this EdmProperty property, object configuration)
        {
            DebugCheck.NotNull(property);

            property.GetMetadataProperties().SetConfiguration(configuration);
        }
Esempio n. 7
0
        public static void SetAllowOverride(this EdmProperty column, bool allowOverride)
        {
            DebugCheck.NotNull(column);

            column.GetMetadataProperties().SetAnnotation(AllowOverrideAnnotation, allowOverride);
        }
Esempio n. 8
0
 public static void SetUnpreferredUniqueName(this EdmProperty tableColumn, string name)
 {
     tableColumn.GetMetadataProperties().SetAnnotation("UnpreferredUniqueName", (object)name);
 }
Esempio n. 9
0
 public static void SetOrder(this EdmProperty tableColumn, int order)
 {
     tableColumn.GetMetadataProperties().SetAnnotation("Order", (object)order);
 }
Esempio n. 10
0
 public static void SetConfiguration(this EdmProperty property, object configuration)
 {
     property.GetMetadataProperties().SetConfiguration(configuration);
 }