Esempio n. 1
0
 private static void EnsureFieldAccess(IMutableEntityType enityType)
 {
     foreach (var navigation in enityType.GetNavigations())
     {
         navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
     }
 }
    private static void AddConvertersForNavigations(
        IMutableEntityType entity,
        ModelBuilder modelBuilder,
        bool validateOnWrite,
        Dictionary <Type, ValueConverter> converterLookup,
        Action <IMutableProperty> configure)
    {
        List <IMutableNavigation>?navigationsToConvert = null;

        foreach (var navigation in entity.GetNavigations())
        {
            if (ValueObjectMetadataLookup.Find(navigation.ClrType) is not null)
            {
                (navigationsToConvert ??= new List <IMutableNavigation>()).Add(navigation);
            }
        }

        if (navigationsToConvert is null)
        {
            return;
        }

        var builders = modelBuilder.FindEntityBuilder(entity);

        foreach (var navigation in navigationsToConvert)
        {
            var property = FindPropertyBuilder(builders, entity, navigation.Name);

            SetConverterAndExecuteCallback(validateOnWrite, converterLookup, configure, property.Metadata);
        }
    }
        private static List <CollectionNavigationDefinition> GetCollectionNavigationDefinition(IMutableEntityType entityType)
        {
            List <CollectionNavigationDefinition> collectionNavDefs = new List <CollectionNavigationDefinition>();
            var inverses =
                entityType.GetNavigations().Where(i => i.ClrType.IsCollection()).Select(i => new { i, InverseType = i.FindInverse() }).Where(i => i.InverseType != null).ToList();

            inverses.ForEach(it =>
            {
                var inverseForeignKeys = it.InverseType.ForeignKey.Properties;
                var principalKeys      = it.InverseType.ForeignKey.PrincipalKey.Properties;
                var foreignKeyPairs    = inverseForeignKeys.Zip(principalKeys,
                                                                (a, b) =>
                                                                new ForeignKeyPairDefinition()
                {
                    DeclaringEntityColumn = new NameTypePairDefinition()
                    {
                        Name = a.Name, Type = a.ClrType
                    },
                    PrincipalEntityColumn = new NameTypePairDefinition()
                    {
                        Name = b.Name, Type = b.ClrType
                    }
                }).ToList();
                var declaredEntity = it.InverseType.DeclaringEntityType;
                collectionNavDefs.Add(new CollectionNavigationDefinition()
                {
                    Navigation = new NameTypePairDefinition()
                    {
                        Name = it.i.Name, Type = it.i.ClrType
                    },
                    ForeignKeys     = foreignKeyPairs,
                    DeclaringEntity = new NameTypePairDefinition()
                    {
                        Name = declaredEntity.Name, Type = declaredEntity.ClrType
                    },
                    PrincipalEntity = new NameTypePairDefinition()
                    {
                        Name = entityType.Name, Type = entityType.ClrType
                    },
                });
            });
            return(collectionNavDefs);
        }
Esempio n. 4
0
 private IEnumerable <IMutableEntityType> DetermineNavigationTypes(IMutableEntityType parentType)
 {
     var navigations = parentType.GetNavigations().Where(nav => nav.PropertyInfo is { });