private IModel CreateModel()
        {
            var model = new Model();
            var builder = new ModelBuilder(model);

            builder.Entity<ClrPoco>()
                .PartitionAndRowKey(s => s.PartitionKey, s => s.RowKey)
                .Timestamp(s => s.Timestamp);

            builder.Entity("ShadowEntity", pb =>
                {
                    pb.Property<object>("PartitionKey", true);
                    pb.Property<object>("RowKey", true);
                    pb.Property<object>("Timestamp", true);
                    pb.Property<object>("SomeProperty", true);
                    pb.Key("PartitionKey", "RowKey");
                });

            builder.Entity<GuidKeysPoco>()
                .PartitionAndRowKey(s => s.PartitionGuid, s => s.RowGuid)
                .Timestamp("Timestamp", true);

            builder.Entity<IntKeysPoco>()
                .PartitionAndRowKey(s => s.PartitionID, s => s.RowID);

            builder.Entity<ClrPocoWithProp>(pb =>
                {
                    pb.PartitionAndRowKey(s => s.PartitionKey, s => s.RowKey);
                    pb.Property(s => s.Timestamp);
                    pb.Property(s => s.StringProp);
                    pb.Property(s => s.IntProp);
                });

            return model;
        }
        public void Get_generation_property_returns_generation_property_from_foreign_key_tree()
        {
            var model = new Model();

            var leftType = new EntityType("Left", model);
            var leftId = leftType.AddProperty("Id", typeof(int), true);
            var leftKey = leftType.AddKey(leftId);

            var rightType = new EntityType("Right", model);
            var rightId1 = rightType.AddProperty("Id1", typeof(int), true);
            var rightId2 = rightType.AddProperty("Id2", typeof(int), true);
            var rightKey = rightType.AddKey(new[] { rightId1, rightId2 });

            var middleType = new EntityType("Middle", model);
            var middleProperty1 = middleType.AddProperty("FK1", typeof(int), true);
            var middleProperty2 = middleType.AddProperty("FK2", typeof(int), true);
            var middleKey1 = middleType.AddKey(middleProperty1);
            var middleFK1 = middleType.AddForeignKey(middleProperty1, leftKey, leftType);
            var middleFK2 = middleType.AddForeignKey(new[] { middleProperty2, middleProperty1 }, rightKey, rightType);

            var endType = new EntityType("End", model);
            var endProperty = endType.AddProperty("FK", typeof(int), true);

            var endFK = endType.AddForeignKey(endProperty, middleKey1, middleType);

            rightId2.RequiresValueGenerator = true;

            Assert.Equal(rightId2, endProperty.GetGenerationProperty());
        }
            public virtual void Finds_existing_navigation_to_principal_and_uses_associated_FK()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<Customer>();
                modelBuilder
                    .Entity<Order>().HasOne(o => o.Customer).WithMany()
                    .ForeignKey(c => c.CustomerId);
                modelBuilder.Ignore<OrderDetails>();
                modelBuilder.Ignore<CustomerDetails>();

                var dependentType = model.GetEntityType(typeof(Order));
                var principalType = model.GetEntityType(typeof(Customer));

                var principalKey = principalType.GetKeys().Single();
                var dependentKey = dependentType.GetKeys().Single();

                modelBuilder.Entity<Order>().HasOne(e => e.Customer).WithMany(e => e.Orders);

                var newFk = dependentType.Navigations.Single().ForeignKey;
                Assert.Equal(nameof(Order.CustomerId), newFk.Properties.Single().Name);
                Assert.Same(newFk, principalType.Navigations.Single().ForeignKey);
                Assert.Empty(principalType.GetForeignKeys());
                Assert.Same(principalKey, principalType.GetKeys().Single());
                Assert.Same(dependentKey, dependentType.GetKeys().Single());
                Assert.Same(principalKey, principalType.GetPrimaryKey());
                Assert.Same(dependentKey, dependentType.GetPrimaryKey());
            }
            public virtual void Replaces_existing_navigation_to_principal()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<CustomerDetails>().Reference(c => c.Customer).InverseReference();
                modelBuilder.Ignore<Order>();

                var dependentType = model.GetEntityType(typeof(CustomerDetails));
                var principalType = model.GetEntityType(typeof(Customer));
                var expectedPrincipalProperties = principalType.Properties.ToList();
                var expectedDependentProperties = dependentType.Properties.ToList();

                var principalKey = principalType.GetKeys().Single();
                var dependentKey = dependentType.GetKeys().Single();

                modelBuilder.Entity<Customer>().Reference(e => e.Details).InverseReference(e => e.Customer);

                var fk = dependentType.GetForeignKeys().Single();
                Assert.Same(fk.DependentToPrincipal, dependentType.Navigations.Single());
                Assert.Same(fk.PrincipalToDependent, principalType.Navigations.Single());
                AssertEqual(expectedPrincipalProperties, principalType.Properties);
                AssertEqual(expectedDependentProperties, dependentType.Properties);
                Assert.Empty(principalType.GetForeignKeys());
                Assert.Same(principalKey, principalType.GetKeys().Single());
                Assert.Same(dependentKey, dependentType.GetKeys().Single());
                Assert.Same(principalKey, principalType.GetPrimaryKey());
                Assert.Same(dependentKey, dependentType.GetPrimaryKey());
            }
Esempio n. 5
0
        protected virtual IModel CreateModel(
            [NotNull] DbContext context,
            [CanBeNull] IConventionSetBuilder conventionSetBuilder,
            [NotNull] IModelValidator validator)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(validator, nameof(validator));

            var conventionSet = CreateConventionSet(conventionSetBuilder);
            var model = new Model();

            model.SetProductVersion(ProductInfo.GetVersion());

            var modelBuilder = new ModelBuilder(conventionSet, model);

            FindSets(modelBuilder, context);

            OnModelCreating(context, modelBuilder);

            modelBuilder.Validate();

            validator.Validate(model);

            return model;
        }
            public virtual void Finds_existing_navigations_and_uses_associated_FK()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<Customer>();
                modelBuilder
                    .Entity<CustomerDetails>().HasOne(d => d.Customer).WithOne(c => c.Details)
                    .ForeignKey<CustomerDetails>(c => c.Id);
                modelBuilder.Ignore<Order>();

                var dependentType = model.GetEntityType(typeof(CustomerDetails));
                var principalType = model.GetEntityType(typeof(Customer));
                var fk = dependentType.GetForeignKeys().Single();

                var navToPrincipal = dependentType.GetNavigation(nameof(CustomerDetails.Customer));
                var navToDependent = principalType.GetNavigation(nameof(Customer.Details));

                var principalKey = principalType.GetKeys().Single();
                var dependentKey = dependentType.GetKeys().Single();

                modelBuilder.Entity<Customer>().HasOne(e => e.Details).WithOne(e => e.Customer);

                Assert.Equal(1, dependentType.GetForeignKeys().Count());
                Assert.Same(navToPrincipal, dependentType.Navigations.Single());
                Assert.Same(navToDependent, principalType.Navigations.Single());
                Assert.Same(fk.PrincipalKey, principalType.Navigations.Single().ForeignKey.PrincipalKey);
                AssertEqual(new[] { "AlternateKey", principalKey.Properties.Single().Name, Customer.NameProperty.Name }, principalType.Properties.Select(p => p.Name));
                AssertEqual(new[] { dependentKey.Properties.Single().Name }, dependentType.Properties.Select(p => p.Name));
                Assert.Empty(principalType.GetForeignKeys());
                Assert.Same(principalKey, principalType.GetKeys().Single());
                Assert.Same(dependentKey, dependentType.GetKeys().Single());
                Assert.Same(principalKey, principalType.GetPrimaryKey());
                Assert.Same(dependentKey, dependentType.GetPrimaryKey());
            }
        public virtual void Detects_shadow_entities()
        {
            var model = new Model();
            model.AddEntityType("A");

            VerifyError(CoreStrings.ShadowEntity("A"), model);
        }
        protected virtual IModel CreateModel(
            [NotNull] DbContext context,
            [CanBeNull] IConventionSetBuilder conventionSetBuilder,
            [NotNull] IModelValidator validator)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(validator, nameof(validator));

            var conventionSet = CreateConventionSet(conventionSetBuilder);
            var model = new Model();

            var productVersion = typeof(ModelSource).GetTypeInfo().Assembly
                .GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
            model[CoreAnnotationNames.ProductVersionAnnotation] = productVersion;

            var modelBuilder = new ModelBuilder(conventionSet, model);

            FindSets(modelBuilder, context);

            OnModelCreating(context, modelBuilder);

            modelBuilder.Validate();

            validator.Validate(model);

            return model;
        }
            public virtual void Finds_existing_navigation_to_principal_and_uses_associated_FK()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<Customer>();
                modelBuilder
                    .Entity<Order>().Reference(c => c.Customer).InverseCollection()
                    .ForeignKey(c => c.CustomerId);
                modelBuilder.Ignore<OrderDetails>();
                modelBuilder.Ignore<CustomerDetails>();

                var dependentType = model.GetEntityType(typeof(Order));
                var principalType = model.GetEntityType(typeof(Customer));
                var fk = dependentType.GetForeignKeys().Single();

                var navigation = dependentType.GetNavigation("Customer");

                var principalKey = principalType.GetKeys().Single();
                var dependentKey = dependentType.GetKeys().Single();

                modelBuilder.Entity<Customer>().Collection(e => e.Orders).InverseReference(e => e.Customer);

                Assert.Equal(1, dependentType.GetForeignKeys().Count());
                Assert.Equal("Orders", principalType.Navigations.Single().Name);
                Assert.Same(fk.PrincipalKey, principalType.Navigations.Single().ForeignKey.PrincipalKey);
                AssertEqual(new[] { "AlternateKey", principalKey.Properties.Single().Name, Customer.NameProperty.Name }, principalType.Properties.Select(p => p.Name));
                AssertEqual(new[] { "AnotherCustomerId", fk.Properties.Single().Name, dependentKey.Properties.Single().Name }, dependentType.Properties.Select(p => p.Name));
                Assert.Empty(principalType.GetForeignKeys());
                Assert.Same(principalKey, principalType.GetKeys().Single());
                Assert.Same(dependentKey, dependentType.GetKeys().Single());
                Assert.Same(principalKey, principalType.GetPrimaryKey());
                Assert.Same(dependentKey, dependentType.GetPrimaryKey());
            }
        protected Model CreateModel()
        {
            var model = new Model();
            var modelBuilder = new BasicModelBuilder(model);

            modelBuilder.Entity<MappingQueryTestBase.MappedCustomer>(e =>
                {
                    e.Key(c => c.CustomerID);
                    e.Property(c => c.CompanyName2).Metadata.Relational().Column = "Broken";
                    e.Metadata.Relational().Table = "Broken";
                    e.Metadata.Relational().Schema = "wrong";
                });

            modelBuilder.Entity<MappingQueryTestBase.MappedEmployee>(e =>
                {
                    e.Key(em => em.EmployeeID);
                    e.Property(em => em.City2).Metadata.Relational().Column = "City";
                    e.Metadata.Relational().Table = "Employees";
                    e.Metadata.Relational().Schema = "dbo";
                });

            modelBuilder.Entity<MappingQueryTestBase.MappedOrder>(e =>
                {
                    e.Key(o => o.OrderID);
                    e.Property(em => em.ShipVia2).Metadata.Relational().Column = "ShipVia";
                    e.Metadata.Relational().Table = "Orders";
                    e.Metadata.Relational().Schema = "dbo";
                });

            OnModelCreating(modelBuilder);

            return model;
        }
        public void Model_can_be_set_explicitly_in_options()
        {
            var model = new Model();

            var optionsBuilder = new DbContextOptionsBuilder().UseModel(model);

            Assert.Same(model, optionsBuilder.Options.FindExtension<CoreOptionsExtension>().Model);
        }
Esempio n. 12
0
 private ForeignKey CreateForeignKey()
 {
     var model = new Model();
     var entityType = model.AddEntityType("E");
     var property = entityType.AddProperty("p", typeof(int), shadowProperty: true);
     var key = entityType.SetPrimaryKey(property);
     return new ForeignKey(new[] { property }, key);
 }
            public virtual void ForeignKeyAttribute_does_not_set_foreign_key_properties_when_applied_on_properties_for_composite_foreign_key()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<PostDetails>();

                Assert.Equal("AuthorId", model.GetEntityType(typeof(PostDetails)).FindNavigation("Author").ForeignKey.Properties.First().Name);
            }
            public virtual void ForeignKeyAttribute_does_not_set_foreign_key_properties_when_names_on_property_and_navigation_do_not_match()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<Author>();

                Assert.Equal("AuthorId", model.GetEntityType(typeof(AuthorDetails)).FindNavigation("Author").ForeignKey.Properties.First().Name);
            }
        public virtual void Detects_a_null_primary_key()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            var property = entityType.AddProperty("Id", typeof(int));

            VerifyError(CoreStrings.EntityRequiresKey(typeof(A).FullName), model);
        }
Esempio n. 16
0
        public void Can_set_model()
        {
            var sequence = new Sequence("Foo");

            var model = new Model();
            sequence.Model = model;
            Assert.Same(model, sequence.Model);
        }
        public void Get_generation_property_returns_null_for_property_without_generator()
        {
            var model = new Model();

            var entityType = new EntityType("Entity", model);
            var property = entityType.AddProperty("Property", typeof(int), true);

            Assert.Null(property.GetGenerationProperty());
        }
Esempio n. 18
0
 private static void AddNavigationToPrincipal(Microsoft.Data.Entity.Metadata.Model model, Type type, string fk, string navigation)
 {
     model.GetEntityType(type)
     .AddNavigation(
         navigation,
         model.GetEntityType(type).ForeignKeys.Single(
             f => f.Properties.Count == 1 && f.Properties.Single().Name == fk),
         pointsToPrincipal: true);
 }
Esempio n. 19
0
 private ForeignKey CreateForeignKey()
 {
     var model = new Model();
     var entityType = model.AddEntityType("E");
     var idProperty = entityType.AddProperty("id", typeof(int));
     var key = entityType.SetPrimaryKey(idProperty);
     var fkProperty = entityType.AddProperty("p", typeof(int));
     return entityType.AddForeignKey(fkProperty, key, entityType);
 }
        public virtual void Detects_a_non_shadow_property_that_doesnt_match_the_CLR_property_type()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            var property = entityType.AddProperty("P0", typeof(string));
            property.IsShadowProperty = false;

            VerifyError(Strings.PropertyWrongClrType("P0", typeof(A).FullName), model);
        }
        public virtual void Detects_shadow_keys()
        {
            var model = new Model();
            var entityType = model.AddEntityType("E");
            var keyProperty = entityType.AddProperty("Id", typeof(int), shadowProperty: true);
            entityType.AddKey(keyProperty);

            VerifyWarning(Strings.ShadowKey("{'Id'}", "E", "{'Id'}"), model);
        }
Esempio n. 22
0
        public void Constructor_validates_properties_from_same_entity()
        {
            var property1 = new Model().AddEntityType(typeof(Customer)).GetOrAddProperty(Customer.IdProperty);
            var property2 = new Model().AddEntityType(typeof(Order)).GetOrAddProperty(Order.IdProperty);

            Assert.Equal(CoreStrings.InconsistentEntityType("properties"),
                Assert.Throws<ArgumentException>(
                    () => new Index(new[] { property1, property2 })).Message);
        }
        public virtual void Detects_a_non_shadow_property_that_doesnt_match_a_CLR_property()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            var property = entityType.AddProperty("Id1", typeof(int));
            property.IsShadowProperty = false;
            entityType.SetPrimaryKey(property);

            VerifyError(CoreStrings.NoClrProperty("Id1", typeof(A).FullName), model);
        }
            public virtual void NotMappedAttribute_removes_ambiguity_in_conventional_relationship_building()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);
                modelBuilder.Entity<Book>();

                Assert.Contains("Details", model.GetEntityType(typeof(Book)).Navigations.Select(nav => nav.Name));
                Assert.Contains("AnotherBook", model.GetEntityType(typeof(BookDetails)).Navigations.Select(nav => nav.Name));
                Assert.DoesNotContain("Book", model.GetEntityType(typeof(BookDetails)).Navigations.Select(nav => nav.Name));
            }
        public virtual void Detects_shadow_keys()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            SetPrimaryKey(entityType);
            var keyProperty = entityType.AddProperty("Key", typeof(int));
            entityType.AddKey(keyProperty);

            VerifyWarning(CoreStrings.ShadowKey("{'Key'}", typeof(A).FullName, "{'Key'}"), model);
        }
            public virtual void Can_get_entity_builder_for_clr_type()
            {
                var model = new Model();
                var modelBuilder = CreateModelBuilder(model);

                var entityBuilder = modelBuilder.Entity<Customer>();

                Assert.NotNull(entityBuilder);
                Assert.Equal(typeof(Customer).FullName, model.GetEntityType(typeof(Customer)).Name);
            }
        public virtual void Detects_self_referencing_properties()
        {
            var model = new Model();
            var entityA = model.AddEntityType(typeof(A));
            var keyA = CreateKey(entityA);

            CreateForeignKey(keyA, keyA);

            VerifyError(Strings.CircularDependency("'A' {'P0'} -> 'A' {'P0'}"), model);
        }
Esempio n. 28
0
        public void Can_get_entity_builder_for_entity_type_name()
        {
            var model = new Model();
            var modelBuilder = new ModelBuilder(model);

            var entityBuilder = modelBuilder.Entity("Customer");

            Assert.NotNull(entityBuilder);
            Assert.NotNull(model.TryGetEntityType("Customer"));
        }
Esempio n. 29
0
        public void Can_create_key_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);

            var key = new Key(new[] { property1, property2 });

            Assert.True(new[] { property1, property2 }.SequenceEqual(key.Properties));
        }
        private static Model CreateModel(bool generateValues = true)
        {
            var model = new Model();

            var entityType = model.AddEntityType("Led");
            entityType.AddProperty("Zeppelin", typeof(Guid));
            entityType.AddProperty("Stairway", typeof(Guid)).RequiresValueGenerator = generateValues;

            return model;
        }
Esempio n. 31
0
 private static void AddNavigationToDependent(Microsoft.Data.Entity.Metadata.Model model, Type type, Type dependentType, string fk1, string fk2, string navigation)
 {
     model.GetEntityType(type)
     .AddNavigation(
         navigation,
         model.GetEntityType(dependentType).ForeignKeys.Single(
             f => f.Properties.Count == 2 &&
             f.Properties.Any(p => p.Name == fk1) &&
             f.Properties.Any(p => p.Name == fk2)),
         pointsToPrincipal: false);
 }
Esempio n. 32
0
        public void Can_set_ClrType()
        {
            var entityType = new Model().AddEntityType(typeof(object));
            var property = entityType.AddProperty("Kake");

            Assert.Null(property.ClrType);
            Assert.Equal(typeof(string), ((IProperty)property).ClrType);

            property.ClrType = typeof(int);
            Assert.Equal(typeof(int), property.ClrType);
        }
Esempio n. 33
0
        public virtual IModel ConstructRelationalModel()
        {
            var relationalModel = new Microsoft.Data.Entity.Metadata.Model();

            foreach (var table in _tables.Values)
            {
                relationalModel.AddEntityType(table.Id);
            }

            foreach (var tc in _tableColumns.Values)
            {
                var entityType = relationalModel.FindEntityType(tc.TableId);
                if (entityType == null)
                {
                    _logger.LogWarning(
                        Strings.CannotFindTableForColumn(tc.Id, tc.TableId));
                    continue;
                }

                // IModel will not allow Properties to be created without a Type, so map to CLR type here.
                // This means if we come across a column with a SQL Server type which we can't map we will ignore it.
                // Note: foreign key properties appear just like any other property in the relational model.
                Type clrPropertyType;
                if (!SqlServerTypeMapping._sqlTypeToClrTypeMap.TryGetValue(tc.DataType, out clrPropertyType))
                {
                    _logger.LogWarning(
                        Strings.CannotFindTypeMappingForColumn(tc.Id, tc.DataType));
                    continue;
                }

                if (tc.IsNullable)
                {
                    clrPropertyType = clrPropertyType.MakeNullable();
                }

                var relationalProperty = entityType.AddProperty(tc.Id, clrPropertyType, shadowProperty: true);
                _relationalColumnIdToRelationalPropertyMap[tc.Id] = relationalProperty;
            }

            return(relationalModel);
        }
        public virtual IModel ConstructCodeGenModel(
            [NotNull] IModel relationalModel, [NotNull] SqlServerNameMapper nameMapper)
        {
            Check.NotNull(relationalModel, nameof(relationalModel));
            Check.NotNull(nameMapper, nameof(nameMapper));

            var codeGenModel = new Microsoft.Data.Entity.Metadata.Model();
            foreach (var relationalEntityType in relationalModel.EntityTypes.Cast<EntityType>())
            {
                var codeGenEntityType = codeGenModel
                    .AddEntityType(nameMapper.EntityTypeToClassNameMap[relationalEntityType]);
                _relationalEntityTypeToCodeGenEntityTypeMap[relationalEntityType] = codeGenEntityType;
                codeGenEntityType.Relational().Table = _tables[relationalEntityType.Name].TableName;
                codeGenEntityType.Relational().Schema = _tables[relationalEntityType.Name].SchemaName;

                // Loop over relational properties constructing a matching property in the 
                // codeGenModel. Also accumulate:
                //    a) primary key properties
                //    b) constraint properties
                var primaryKeyProperties = new List<Property>();
                var constraints = new Dictionary<string, List<Property>>();
                _relationalEntityTypeToForeignKeyConstraintsMap[relationalEntityType] = constraints;
                foreach (var relationalProperty in relationalEntityType.Properties)
                {
                    int primaryKeyOrdinal;
                    if (_primaryKeyOrdinals.TryGetValue(relationalProperty.Name, out primaryKeyOrdinal))
                    {
                        // add _relational_ property so we can order on the ordinal later
                        primaryKeyProperties.Add(relationalProperty);
                    }

                    Dictionary<string, int> foreignKeyConstraintIdOrdinalMap;
                    if (_foreignKeyOrdinals.TryGetValue(relationalProperty.Name, out foreignKeyConstraintIdOrdinalMap))
                    {
                        // relationalProperty represents (part of) a foreign key
                        foreach (var constraintId in foreignKeyConstraintIdOrdinalMap.Keys)
                        {
                            List<Property> constraintProperties;
                            if (!constraints.TryGetValue(constraintId, out constraintProperties))
                            {
                                constraintProperties = new List<Property>();
                                constraints.Add(constraintId, constraintProperties);
                            }
                            constraintProperties.Add(relationalProperty);
                        }
                    }

                    var codeGenProperty = codeGenEntityType.AddProperty(
                        nameMapper.PropertyToPropertyNameMap[relationalProperty],
                        relationalProperty.ClrType,
                        shadowProperty: true);
                    _relationalPropertyToCodeGenPropertyMap[relationalProperty] = codeGenProperty;
                    ApplyPropertyProperties(codeGenProperty, _tableColumns[relationalProperty.Name]);
                } // end of loop over all relational properties for given EntityType

                if (primaryKeyProperties.Count() > 0)
                {
                    // order the relational properties by their primaryKeyOrdinal, then return a list
                    // of the codeGen properties mapped to each relational property in that order
                    codeGenEntityType.SetPrimaryKey(
                        primaryKeyProperties
                        .OrderBy(p => _primaryKeyOrdinals[p.Name]) // note: for relational property p.Name is its columnId
                        .Select(p => _relationalPropertyToCodeGenPropertyMap[p])
                        .ToList());
                }
                else
                {
                    var errorMessage = Strings.NoPrimaryKeyColumns(
                        codeGenEntityType.Name,
                        _tables[relationalEntityType.Name].SchemaName,
                        _tables[relationalEntityType.Name].TableName);
                    codeGenEntityType.AddAnnotation(AnnotationNameEntityTypeError, errorMessage);
                    _logger.LogWarning(Strings.CannotGenerateEntityType(codeGenEntityType.Name, errorMessage));
                }
            } // end of loop over all relational EntityTypes

            AddForeignKeysToCodeGenModel(codeGenModel);

            return codeGenModel;
        }