• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Metadata.Model类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Data.Entity.Metadata.Model的典型用法代码示例。如果您正苦于以下问题:C# Model类的具体用法?C# Model怎么用?C# Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Model类属于Microsoft.Data.Entity.Metadata命名空间,在下文中一共展示了Model类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Replaces_existing_navigation_to_principal

            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());
            }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:28,代码来源:OneToOneTestBase.cs


示例2: CreateModel

        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;
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:33,代码来源:MappingQueryFixtureBase.cs


示例3: CreateModel

        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;
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:35,代码来源:StateEntryTableEntityAdapterTest.cs


示例4: CreateModel

        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;
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:25,代码来源:ModelSource.cs


示例5: Get_generation_property_returns_generation_property_from_foreign_key_tree

        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());
        }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:29,代码来源:PropertyExtensionsTest.cs


示例6: Finds_existing_navigation_to_principal_and_uses_associated_FK

            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());
            }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:33,代码来源:OneToManyTestBase.cs


示例7: Finds_existing_navigations_and_uses_associated_FK

            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());
            }
开发者ID:491134648,项目名称:EntityFramework,代码行数:34,代码来源:OneToOneTestBase.cs


示例8: Finds_existing_navigation_to_principal_and_uses_associated_FK

            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());
            }
开发者ID:491134648,项目名称:EntityFramework,代码行数:28,代码来源:ManyToOneTestBase.cs


示例9: Detects_shadow_entities

        public virtual void Detects_shadow_entities()
        {
            var model = new Model();
            model.AddEntityType("A");

            VerifyError(CoreStrings.ShadowEntity("A"), model);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:7,代码来源:ModelValidatorTest.cs


示例10: CreateModel

        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;
        }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:27,代码来源:ModelSource.cs


示例11: CreateForeignKey

 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);
 }
开发者ID:thegido,项目名称:EntityFramework,代码行数:8,代码来源:NavigationTest.cs


示例12: Can_set_model

        public void Can_set_model()
        {
            var sequence = new Sequence("Foo");

            var model = new Model();
            sequence.Model = model;
            Assert.Same(model, sequence.Model);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:8,代码来源:SequenceTest.cs


示例13: Model

            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);
            }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:8,代码来源:DataAnnotationsTestBase.cs


示例14: Model_can_be_set_explicitly_in_options

        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);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:8,代码来源:DbContextOptionsTest.cs


示例15: Detects_a_null_primary_key

        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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:8,代码来源:ModelValidatorTest.cs


示例16: CreateForeignKey

 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);
 }
开发者ID:491134648,项目名称:EntityFramework,代码行数:9,代码来源:NavigationTest.cs


示例17: Constructor_validates_properties_from_same_entity

        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);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:9,代码来源:IndexTest.cs


示例18: Get_generation_property_returns_null_for_property_without_generator

        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());
        }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:9,代码来源:PropertyExtensionsTest.cs


示例19: Detects_a_non_shadow_property_that_doesnt_match_the_CLR_property_type

        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);
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:9,代码来源:ModelValidatorTest.cs


示例20: Detects_shadow_keys

        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);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:9,代码来源:ModelValidatorTest.cs



注:本文中的Microsoft.Data.Entity.Metadata.Model类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# OData.ODataEntry类代码示例发布时间:2022-05-26
下一篇:
C# Commands.CommandProcessorContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap