当前位置: 首页>>代码示例>>C#>>正文


C# DbModelBuilder.ComplexType方法代码示例

本文整理汇总了C#中DbModelBuilder.ComplexType方法的典型用法代码示例。如果您正苦于以下问题:C# DbModelBuilder.ComplexType方法的具体用法?C# DbModelBuilder.ComplexType怎么用?C# DbModelBuilder.ComplexType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbModelBuilder的用法示例。


在下文中一共展示了DbModelBuilder.ComplexType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Explicitly_mapping_a_DbGeography_property_on_a_complex_type_using_4_1_throws

        public void Explicitly_mapping_a_DbGeography_property_on_a_complex_type_using_4_1_throws()
        {
            var modelBuilder = new DbModelBuilder(DbModelBuilderVersion.V4_1);

            modelBuilder.ComplexType<Spatial_ComplexType>().Property(c => c.Geography);

            Assert.Throws<NotSupportedException>(
                () =>
                BuildMapping(modelBuilder))
                .ValidateMessage("UnsupportedUseOfV3Type", "Spatial_ComplexType", "Geography");
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:SpatialScenarioTests.cs

示例2: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.ComplexType<Address>();
            modelBuilder.ComplexType<Contact>();
            modelBuilder.Entity<Session>()
                .HasRequired(e => e.Speaker)
                .WithMany().Map(e => e.MapKey("SpeakerId"));
            modelBuilder.Entity<Session>()
                .HasRequired(e => e.Event)
                .WithMany().Map(e => e.MapKey("EventId"));
            modelBuilder.Entity<SpeakerPicture>()
                .HasRequired(e => e.Speaker)
                .WithMany()
                .Map(e => e.MapKey("SpeakerId"));

            modelBuilder.Entity<Speaker>().Property(e => e.Address.Street).HasColumnName("Street");
            modelBuilder.Entity<Speaker>().Property(e => e.Address.ZipCode).HasColumnName("ZipCode");
            modelBuilder.Entity<Speaker>().Property(e => e.Address.City).HasColumnName("City");
            modelBuilder.Entity<Speaker>().Property(e => e.Address.Country).HasColumnName("Country");

            modelBuilder.Entity<Speaker>().Property(e => e.Contact.EMail).HasColumnName("EMail");
            modelBuilder.Entity<Speaker>().Property(e => e.Contact.Fax).HasColumnName("Fax");
            modelBuilder.Entity<Speaker>().Property(e => e.Contact.Phone).HasColumnName("Phone");
            modelBuilder.Entity<Speaker>().Property(e => e.Contact.Homepage).HasColumnName("Homepage");

            modelBuilder.Entity<Vote>()
                        .HasKey(v => new {
                            v.SessionId,
                            v.WebUserId
                        });

            base.OnModelCreating(modelBuilder);
        }
开发者ID:dotnet-koelnbonn,项目名称:SpeakerNet,代码行数:33,代码来源:SpeakerNetDbContext.cs

示例3: SetupModel

        internal static void SetupModel(DbModelBuilder builder)
        {
            builder.Entity<Employee>();
            builder.Entity<Building>()
                .HasOptional(b => b.PrincipalMailRoom)
                .WithMany()
                .HasForeignKey(b => b.PrincipalMailRoomId);

            builder.ComplexType<Address>();
            builder.ComplexType<SiteInfo>();
            builder.Entity<MailRoom>()
                .HasRequired(m => m.Building)
                .WithMany(b => b.MailRooms)
                .HasForeignKey(m => m.BuildingId);

            builder.Entity<Office>().HasKey(
                o => new
                         {
                             o.Number,
                             o.BuildingId
                         });
            builder.Ignore<UnMappedOffice>();
            builder.Entity<BuildingDetail>()
                .HasKey(d => d.BuildingId)
                .HasRequired(d => d.Building).WithOptional();

            builder.Entity<Building>().Ignore(b => b.NotInModel);
            builder.ComplexType<Address>().Ignore(a => a.County);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:29,代码来源:AdvancedPatternsMasterContext.cs

示例4: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<ReorderedBlogPost>().ToTable("BlogPosts");
            modelBuilder.ComplexType<AuthorInfo>();
            modelBuilder.ComplexType<Address>();

        }
开发者ID:ArthurYiL,项目名称:EntityFramework.Utilities,代码行数:8,代码来源:ReorderedContext.cs

示例5: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<EntityWithComplexType>();
            modelBuilder.Entity<ValidatableEntity>();

            modelBuilder.ComplexType<ComplexTypeWithNoValidation>();
            modelBuilder.ComplexType<ValidatableComplexType>();
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:EntityValidatorBuilderTests.cs

示例6: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder mb)
        {
            mb.ComplexType<Contact>();
            mb.ComplexType<Address>();

            mb.Entity<Foo>().ToTable("Foos", "dbx");
            mb.Entity<Foo>().Property(x => x.Z).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            mb.Ignore<FooExtended>();

            mb.Entity<TestUser>().ToTable("Users");
            mb.Entity<TestUser>().HasKey(x => x.Id);
            mb.Entity<TestUser>().Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            mb.Entity<TestUser>().Property(x => x.FirstName).HasColumnName("Name");
            mb.Entity<TestUser>().Ignore(x => x.FullName);

            mb.Entity<Page>().HasKey(x => x.PageId);
            mb.Entity<Page>().Property(x => x.Title).HasMaxLength(255);
            mb.Entity<Page>().HasOptional(x => x.Parent).WithMany().HasForeignKey(x => x.ParentId);

            mb.Entity<PageTranslations>().HasKey(x => new {x.PageId, x.Language});
            mb.Entity<PageTranslations>().Property(x => x.Title).HasMaxLength(255);

            mb.Entity<EmployeeTPH>().Property(x => x.Title).HasColumnName("JobTitle");
            mb.Entity<EmployeeTPH>().Ignore(x => x.NameWithTitle);
            mb.Entity<EmployeeTPH>()
                .Map<AWorkerTPH>(m => m.Requires("__employeeType").HasValue(1))
                .Map<ManagerTPH>(m => m.Requires("__employeeType").HasValue(2));

            mb.Entity<AWorkerTPH>().HasRequired(x => x.Boss).WithMany(x => x.Henchmen).HasForeignKey(x => x.BossId);
            
            mb.Entity<WorkerTPT>().HasRequired(x => x.Boss).WithMany(x => x.Henchmen);


            mb.Entity<ContractBase>().HasRequired(x => x.MeteringPoint).WithMany().HasForeignKey(x => x.MeteringPointId).WillCascadeOnDelete(false);
            mb.Entity<ContractBase>().Property(x => x.PackageName).HasMaxLength(50);
            mb.Entity<ContractBase>().Property(x => x.ContractNr).HasMaxLength(50);
            mb.Entity<ContractBase>().Property(x => x.AvpContractNr).HasMaxLength(50);

            mb.Entity<ContractBase>()
                .Map(x => x.ToTable("Contracts"))
                .Map<Contract>(x => x.Requires(ContractDiscriminator).HasValue(0))
                .Map<ContractFixed>(x => x.Requires(ContractDiscriminator).HasValue(1))
                .Map<ContractStock>(x => x.Requires(ContractDiscriminator).HasValue(2))
                .Map<ContractKomb1>(x => x.Requires(ContractDiscriminator).HasValue(3))
                .Map<ContractKomb2>(x => x.Requires(ContractDiscriminator).HasValue(4));

            mb.Entity<ContractStock>().Property(x => x.Margin).HasPrecision(18, 6);

            mb.Entity<ContractKomb1>().Property(x => x.Base).HasPrecision(18, 4);
            mb.Entity<ContractKomb1>().Property(x => x.StockMargin).HasPrecision(18, 6).HasColumnName("Margin1");
            mb.Entity<ContractKomb1>().Property(x => x.FixPricesJson).HasColumnName("PricesJson1");

            mb.Entity<ContractKomb2>().Property(x => x.Part1Margin).HasPrecision(18, 6);
            mb.Entity<ContractKomb2>().Property(x => x.Part2Margin).HasPrecision(18, 6);

            base.OnModelCreating(mb);
        }
开发者ID:akry1,项目名称:EntityFramework.BulkInsert,代码行数:57,代码来源:TestBaseContext.cs

示例7: OnModelCreating

 /// <summary>
 /// Is called when model is created.
 /// </summary>
 /// <param name="modelBuilder">The model builder.</param>
 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
   base.OnModelCreating(modelBuilder);
   modelBuilder.Entity<LogEntry>().ToTable("LogEntries");
   modelBuilder.Entity<LogEntry>().HasKey(k => k.LogEntryID);
   modelBuilder.ComplexType<LogEntryDetails>().Property(p => p.MessageKey).HasColumnName("Details");
   modelBuilder.ComplexType<LogEntryDetails>().Property(p => p.FormattedParameters).HasColumnName("Parameters");
   modelBuilder.ComplexType<LogEntryDetails>().Ignore(p => p.Message);
   modelBuilder.ComplexType<Severity>().Property(p => p.SeverityLevel).HasColumnName("Severity");
 }
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:14,代码来源:LoggingModel.cs

示例8: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Configurations.Add(new MemberMap());
            modelBuilder.Configurations.Add(new PersonalInformationMap());
            modelBuilder.Configurations.Add(new RankMap());

            // Complex Types
            modelBuilder.ComplexType<AccountNo>()
                .Property(m => m.Number)
                .HasColumnName("AccountNo");

            modelBuilder.ComplexType<Address>()
                .Property(m => m.Line1)
                .HasColumnName("AddressLine1")
                .IsOptional();

            modelBuilder.ComplexType<Address>()
                .Property(m => m.Line2)
                .HasColumnName("AddressLine2")
                .IsOptional();

            modelBuilder.ComplexType<Address>()
                .Property(m => m.City)
                .HasColumnName("City")
                .IsRequired();

            modelBuilder.ComplexType<Address>()
                .Property(m => m.Country)
                .HasColumnName("Country")
                .IsRequired();

            modelBuilder.ComplexType<FullName>()
                .Property(m => m.Title)
                .HasColumnName("Title")
                .IsOptional();

            modelBuilder.ComplexType<FullName>()
                .Property(m => m.FirstName)
                .HasColumnName("FirstName")
                .IsRequired();

            modelBuilder.ComplexType<FullName>()
                .Property(m => m.LastName)
                .HasColumnName("LastName")
                .IsRequired();

            modelBuilder.ComplexType<EmiratesId>().Property(m => m.Number)
                .HasColumnName("EmiratesId")
                .IsRequired();

            modelBuilder.ComplexType<Email>().Property(m => m.EmailAddress)
                .HasColumnName("Email")
                .IsRequired();

            modelBuilder.ComplexType<Mobile>().Property(m => m.Number)
                .HasColumnName("Mobile")
                .IsRequired();
        }
开发者ID:Daskul,项目名称:BIG,代码行数:59,代码来源:MembershipContext.cs

示例9: OnModelCreating

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
     //утановка полей NOT NULL
     modelBuilder.Entity<History>().Property(c => c.HistoryId).IsRequired();
     modelBuilder.Entity<History>().Property(c => c.X).IsRequired();
     modelBuilder.Entity<History>().Property(c => c.Y).IsRequired();
     //класс History не является самостоятельной таблицей, на языке EF это сложный комплексный тип, поскольку содержит
     //внутри поле сложного типа Player. Для создания обычного комплексного типа
     //(не содержащего внутри полей ссылочного типа) достаточно удалить из модели
     //свойство, хранящее уникальный ключ. Ниже происходит настройка сложного типа History. Также для этого
     //можно исп-ть атрибут [ComplexType], указываемый над созданной моделью сложного типа.
     modelBuilder.ComplexType<History>().Property(x => x.X).HasColumnType("smallint");
     modelBuilder.ComplexType<History>().Property(x => x.Y).HasColumnType("smallint");
 }
开发者ID:AzarinSergey,项目名称:velvetech,代码行数:14,代码来源:History.cs

示例10: OnModelCreating

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new SaleMap());
            modelBuilder.Configurations.Add(new CustomerMap());
            modelBuilder.Configurations.Add(new ServiceTypeMap());
            modelBuilder.Configurations.Add(new SaleCommissionMap());

            modelBuilder.ComplexType<Email>()
                .Property(m => m.EmailAddress)
                .HasColumnName("Email");

            modelBuilder.ComplexType<Mobile>()
                .Property(m => m.Number)
                .HasColumnName("Mobile");
        }
开发者ID:Daskul,项目名称:BIG,代码行数:15,代码来源:SalesContext.cs

示例11: EnsureDatabase

        public static void EnsureDatabase(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            modelBuilder.ComplexType<Money>();
            modelBuilder.ComplexType<Address>();
            modelBuilder.ComplexType<CreditCard>();

            modelBuilder.Configurations.Add(new ExpiryDateMap());
            modelBuilder.Configurations.Add(new FidelityCardMap());
            modelBuilder.Configurations.Add(new OrderMap());
            modelBuilder.Configurations.Add(new CurrencyMap());
            modelBuilder.Configurations.Add(new OrderItemMap());
            modelBuilder.Configurations.Add(new CustomerMap());
            modelBuilder.Configurations.Add(new AdminMap());
        }
开发者ID:pachinko,项目名称:naa4e,代码行数:16,代码来源:CommandModelDatabase.cs

示例12: CreaModelloComune

        private void CreaModelloComune(DbModelBuilder modelBuilder)
        {
            modelBuilder.ComplexType<Area>();

            modelBuilder.Entity<Competenza>()
                .Map(m => m.ToTable("Competenze"));

            modelBuilder.Entity<ConoscenzaCompetenza>()
                .Map(m => m.ToTable("ConoscenzeCompetenza"));
            //.HasRequired(m => m.Dotato).WithRequiredPrincipal().WillCascadeOnDelete();


            /*modelBuilder.Entity<Ruolo>()
                .Map(m =>m.ToTable("Ruoli"));*/
            modelBuilder.Entity<Anagrafica>()
               .Map(m => m.ToTable("Anagrafica"))
               .Map<Dipendente>(m => m.Requires("Tipo").HasValue("DIP"))
               .Map<Ruolo>(m => m.Requires("Tipo").HasValue("ROLE"));


            modelBuilder.Entity<LivelloConoscenza>()
                .Map(m => m.ToTable("LivelliConoscenza"));


            modelBuilder.Entity<TipologiaCompetenza>()
                .Map(m => m.ToTable("TipologieCompetenza"));


            modelBuilder.Entity<Parametro>()
                .HasKey(m => m.Nome)
                .Map(m => m.ToTable("Parametri"));
        }
开发者ID:salem84,项目名称:GeCo.Survey,代码行数:32,代码来源:SurveyContext.cs

示例13: Can_configure_complex_column_name_after_entity_splitting

        public void Can_configure_complex_column_name_after_entity_splitting()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.ComplexType<ComplexTypeWithColumnRename>();

            modelBuilder.Entity<EntityWithColumnsRename>()
                .Map(
                    mapping =>
                        {
                            mapping.ToTable("Table1");
                            mapping.Properties(e => e.Property1);
                        });

            modelBuilder.Entity<EntityWithColumnsRename>()
                .Map(
                    mapping =>
                        {
                            mapping.ToTable("Table2");
                            mapping.Properties(e => e.Property2);
                            mapping.Properties(e => e.ComplexProp);
                        });

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();
            databaseMapping.Assert<EntityWithColumnsRename>("Table2").HasColumn("ColumnFor_Details");
        }
开发者ID:,项目名称:,代码行数:28,代码来源:

示例14: AdditionalModelConfiguration

 public static void AdditionalModelConfiguration(DbModelBuilder modelBuilder)
 {
     modelBuilder.Entity<Chassis>().HasRequired(c => c.Team).WithRequiredDependent(t => t.Chassis).WillCascadeOnDelete();
     modelBuilder.ComplexType<Location>();
     modelBuilder.Entity<Sponsor>().ToTable("Sponsors");
     modelBuilder.Entity<TitleSponsor>().ToTable("TitleSponsors");
 }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:7,代码来源:F1Context.cs

示例15: OnModelCreating

		protected override void OnModelCreating( DbModelBuilder modelBuilder )
		{
			base.OnModelCreating( modelBuilder );

			modelBuilder.Entity<Address>()
					.ToTable( "dbo.PersonAddresses" );
			modelBuilder.MapPropertiesOf<Address>();

			modelBuilder.ComplexType<BornInfo>();

			var person = modelBuilder.Entity<Person>();
			person.HasMany( p => p.Addresses )
				.WithOptional()
				.HasForeignKey( a => a.PersonId )
				.WillCascadeOnDelete();

			modelBuilder.MapPropertiesOf<Person>(

				propertiesToSkip: new[] 
				{
					ReflectionHelper.GetPropertyName<Person>( p => p.Info ), 
					ReflectionHelper.GetPropertyName<Person>( p => p.Addresses ) 
				} );

			var companyState = modelBuilder.Entity<Company.State>()
				.ToTable( "Companies" );
			modelBuilder.MapPropertiesOf<Company.State>();
		}
开发者ID:nazarenomanco,项目名称:Radical.CQRS,代码行数:28,代码来源:SampleDomainContext.cs


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