private static ForeignKey?CreateSkipNavigationForeignKey(
     SkipNavigation skipNavigation,
     InternalEntityTypeBuilder joinEntityTypeBuilder)
 => joinEntityTypeBuilder
 .HasRelationship(
     skipNavigation.DeclaringEntityType,
     ConfigurationSource.Convention,
     required: true,
     skipNavigation.Inverse !.Name) !
示例#2
0
 private static ForeignKey CreateSkipNavigationForeignKey(
     SkipNavigation skipNavigation,
     InternalEntityTypeBuilder joinEntityTypeBuilder)
 => joinEntityTypeBuilder
 .HasRelationship(
     skipNavigation.DeclaringEntityType,
     ConfigurationSource.Convention,
     required: true)
 .IsUnique(false, ConfigurationSource.Convention)
 .Metadata;
示例#3
0
        private static ForeignKey CreateSkipNavigationForeignKey(
            SkipNavigation skipNavigation,
            InternalEntityTypeBuilder associationEntityTypeBuilder)
        {
            var principalEntityType = skipNavigation.DeclaringEntityType;
            var principalKey        = principalEntityType.FindPrimaryKey();

            if (principalKey == null)
            {
                return(null);
            }

            var dependentEndForeignKeyPropertyNames = new List <string>();
            var otherIdentifiers = associationEntityTypeBuilder.Metadata
                                   .GetDeclaredProperties().ToDictionary(p => p.Name, p => 0);

            foreach (var property in principalKey.Properties)
            {
                var propertyName = Uniquifier.Uniquify(
                    string.Format(
                        AssociationPropertyNameTemplate,
                        principalEntityType.ShortName(),
                        property.Name),
                    otherIdentifiers,
                    int.MaxValue);
                dependentEndForeignKeyPropertyNames.Add(propertyName);
                otherIdentifiers.Add(propertyName, 0);
            }

            return(associationEntityTypeBuilder
                   .HasRelationship(
                       principalEntityType.Name,
                       dependentEndForeignKeyPropertyNames,
                       principalKey,
                       ConfigurationSource.Convention)
                   .IsUnique(false, ConfigurationSource.Convention)
                   .Metadata);
        }
示例#4
0
        public void Every_eventId_has_a_logger_method_and_logs_when_level_enabled()
        {
            var propertyInfo    = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.Now));
            var entityType      = new Model().AddEntityType(typeof(object), ConfigurationSource.Convention);
            var property        = entityType.AddProperty("A", typeof(int), ConfigurationSource.Convention, ConfigurationSource.Convention);
            var otherEntityType = new EntityType(typeof(object), entityType.Model, ConfigurationSource.Convention);
            var otherProperty   = otherEntityType.AddProperty(
                "A", typeof(int), ConfigurationSource.Convention, ConfigurationSource.Convention);
            var otherKey       = otherEntityType.AddKey(otherProperty, ConfigurationSource.Convention);
            var foreignKey     = new ForeignKey(new[] { property }, otherKey, entityType, otherEntityType, ConfigurationSource.Convention);
            var navigation     = new Navigation("N", propertyInfo, null, foreignKey);
            var skipNavigation = new SkipNavigation(
                "SN", propertyInfo, null, entityType, otherEntityType, true, false, ConfigurationSource.Convention);
            var navigationBase = new FakeNavigationBase("FNB", ConfigurationSource.Convention, entityType);

            entityType.Model.FinalizeModel();
            var options = new DbContextOptionsBuilder()
                          .UseInternalServiceProvider(InMemoryFixture.DefaultServiceProvider)
                          .UseInMemoryDatabase("D").Options;

            var fakeFactories = new Dictionary <Type, Func <object> >
            {
                { typeof(Type), () => typeof(object) },
示例#5
0
        public void Every_eventId_has_a_logger_method_and_logs_when_level_enabled()
        {
            var propertyInfo    = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.Now));
            var entityType      = new Model().AddEntityType(typeof(object), ConfigurationSource.Convention);
            var property        = entityType.AddProperty("A", typeof(int), ConfigurationSource.Convention, ConfigurationSource.Convention);
            var otherEntityType = new EntityType(typeof(object), entityType.Model, ConfigurationSource.Convention);
            var otherProperty   = otherEntityType.AddProperty(
                "A", typeof(int), ConfigurationSource.Convention, ConfigurationSource.Convention);
            var otherKey       = otherEntityType.AddKey(otherProperty, ConfigurationSource.Convention);
            var foreignKey     = new ForeignKey(new[] { property }, otherKey, entityType, otherEntityType, ConfigurationSource.Convention);
            var navigation     = new Navigation("N", propertyInfo, null, foreignKey);
            var skipNavigation = new SkipNavigation(
                "SN", propertyInfo, null, entityType, otherEntityType, true, false, ConfigurationSource.Convention);
            var navigationBase = new FakeNavigationBase("FNB", ConfigurationSource.Convention, entityType);

            entityType.Model.FinalizeModel();
            var options = new DbContextOptionsBuilder()
                          .UseInternalServiceProvider(InMemoryFixture.DefaultServiceProvider)
                          .UseInMemoryDatabase("D").Options;

            var fakeFactories = new Dictionary <Type, Func <object> >
            {
                { typeof(Type), () => typeof(object) },
                { typeof(DbContext), () => new DbContext(options) },
                { typeof(DbContextOptions), () => options },
                { typeof(string), () => "Fake" },
                { typeof(ExpressionPrinter), () => new ExpressionPrinter() },
                { typeof(Expression), () => Expression.Constant("A") },
                { typeof(IEntityType), () => entityType },
                { typeof(IReadOnlyEntityType), () => entityType },
                { typeof(IConventionEntityType), () => entityType },
                { typeof(IKey), () => new Key(new[] { property }, ConfigurationSource.Convention) },
                { typeof(IPropertyBase), () => property },
                { typeof(IReadOnlyProperty), () => property },
                { typeof(IServiceProvider), () => new FakeServiceProvider() },
                { typeof(ICollection <IServiceProvider>), () => new List <IServiceProvider>() },
                { typeof(IReadOnlyList <IPropertyBase>), () => new[] { property } },
                { typeof(IReadOnlyList <IReadOnlyPropertyBase>), () => new[] { property } },
                {
                    typeof(IEnumerable <Tuple <MemberInfo, Type> >),
                    () => new[] { new Tuple <MemberInfo, Type>(propertyInfo, typeof(object)) }
                },
                { typeof(MemberInfo), () => propertyInfo },
                { typeof(IReadOnlyList <Exception>), () => new[] { new Exception() } },
                { typeof(IProperty), () => property },
                { typeof(INavigation), () => navigation },
                { typeof(IReadOnlyNavigation), () => navigation },
                { typeof(ISkipNavigation), () => skipNavigation },
                { typeof(IReadOnlySkipNavigation), () => skipNavigation },
                { typeof(INavigationBase), () => navigationBase },
                { typeof(IForeignKey), () => foreignKey },
                { typeof(IReadOnlyForeignKey), () => foreignKey },
                { typeof(InternalEntityEntry), () => new FakeInternalEntityEntry(entityType) },
                { typeof(ISet <object>), () => new HashSet <object>() },
                {
                    typeof(IList <IDictionary <string, string> >),
                    () => new List <IDictionary <string, string> > {
                        new Dictionary <string, string> {
                            { "A", "B" }
                        }
                    }
                },
                { typeof(IDictionary <string, string>), () => new Dictionary <string, string>() }
            };

            TestEventLogging(
                typeof(CoreEventId),
                typeof(CoreLoggerExtensions),
                typeof(TestLoggingDefinitions),
                fakeFactories);
        }