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

C# ModelBuilder类代码示例

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

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



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

示例1: OnModelCreating

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
     {
         relationship.DeleteBehavior = DeleteBehavior.Restrict;
     }
 }
开发者ID:gitter-badger,项目名称:QueueDodge,代码行数:7,代码来源:QueueDodgeDB.cs


示例2: OnModelCreating

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     modelBuilder.Entity<KettleChips>()
         .Property(e => e.BestBuyDate)
         .StoreGeneratedPattern(StoreGeneratedPattern.Identity)
         .DefaultValue(new DateTime(2035, 9, 25));
 }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:7,代码来源:DefaultValuesTest.cs


示例3: OnModelCreating

        public override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<CustomerOrderHistory>().HasKey(coh => coh.ProductName);
            modelBuilder.Entity<MostExpensiveProduct>().HasKey(mep => mep.TenMostExpensiveProducts);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:7,代码来源:NorthwindSprocQueryRelationalFixture.cs


示例4: OnModelCreating

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<LpaUser>(e =>
            {
                e.Key(p => p.Id);

                e.Property(p => p.Id).UseSqlServerSequenceHiLo("LpaUserSeq", "dbo");
                e.Property(p => p.Username).MaxLength(120).Required();
                e.Property(p => p.Password).MaxLength(150).Required();
                e.Property(p => p.PasswordSalt).MaxLength(100).Required();
                e.Property(p => p.Created).Required().ValueGeneratedNever().HasSqlServerDefaultValueSql("sysdatetime()");

                e.Collection(p => p.Claims).InverseReference(p => p.User);
                e.ToSqlServerTable("Users");
            });

            modelBuilder.Entity<LpaUserClaim>(e =>
            {
                e.Key(p=>new { p.UserId, p.ClaimId }).SqlServerClustered();
                e.Reference(p => p.Claim).InverseCollection(p => p.Users).Required();
                e.Reference(p => p.User).InverseCollection(p => p.Claims).Required();
                e.ToSqlServerTable("UserClaims");
            });

            modelBuilder.Entity<LpaClaim>(e =>
            {
                e.Key(p => p.Id).SqlServerClustered();
                e.Property(p => p.Name).MaxLength(125).Required();
                e.Property(p => p.Value).MaxLength(150).Required();
                e.Collection(p => p.Users).InverseReference(p => p.Claim);
                e.ToSqlServerTable("Claims");
            });
        }
开发者ID:nteague22,项目名称:LPA-Site,代码行数:33,代码来源:AuthContext.cs


示例5: BuildModel

        public override void BuildModel(ModelBuilder builder)
        {
            builder
                .Annotation("ProductVersion", "7.0.0-beta6-13815");

            builder.Entity("EF7ProjectLemon.Auth", b =>
                {
                    b.Property<int>("AuthId")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("Login");

                    b.Key("AuthId");
                });

            builder.Entity("EF7ProjectLemon.Person", b =>
                {
                    b.Property<int>("PersonId")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("Name");

                    b.Key("PersonId");
                });
        }
开发者ID:AVVlasov,项目名称:EF7ProjectLemon,代码行数:25,代码来源:LemonContextModelSnapshot.cs


示例6: CreateModel

        protected Model CreateModel()
        {
            var modelBuilder = new ModelBuilder(new ConventionSet());

            modelBuilder.Entity<MappingQueryTestBase.MappedCustomer>(e =>
                {
                    e.Key(c => c.CustomerID);
                    e.Property(c => c.CompanyName2).Metadata.Relational().Column = "Broken";
                    e.Metadata.Relational().Table = "Broken";
                    if (!string.IsNullOrEmpty(DatabaseSchema))
                    {
                        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 = DatabaseSchema;
                });

            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 = DatabaseSchema;
                });

            OnModelCreating(modelBuilder);

            return modelBuilder.Model;
        }
开发者ID:JamesWang007,项目名称:EntityFramework,代码行数:35,代码来源:MappingQueryFixtureBase.cs


示例7: BuildModel

        public override void BuildModel(ModelBuilder builder)
        {
            builder
                .Annotation("ProductVersion", "7.0.0-beta6-13815");

            builder.Entity("OoadProjekatBaza.RestoranBaza.Models.Restoran", b =>
                {
                    b.Property<int>("RestoranId")
                        .ValueGeneratedOnAdd();

                    b.Property<float>("GeoDuzina");

                    b.Property<float>("GeoSirina");

                    b.Property<string>("Naziv");

                    b.Property<string>("Opis");

                    b.Property<float>("Rating");

                    b.Property<byte[]>("Slika")
                        .Annotation("Relational:ColumnType", "image");

                    b.Property<string>("Telefon");

                    b.Property<string>("fourSqaureId");

                    b.Key("RestoranId");
                });
        }
开发者ID:ooad-2015-2016,项目名称:Obavijesti,代码行数:30,代码来源:RestoranDbContextModelSnapshot.cs


示例8: OnModelCreating

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     // Make Blog.Url required
     modelBuilder.Entity<Blog>()
         .Property(b => b.Url)
         .IsRequired();
 }
开发者ID:peterblazejewicz,项目名称:ef-generator-aspnet,代码行数:7,代码来源:Model.cs


示例9: BuildModel

        protected override void BuildModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .Annotation("ProductVersion", "7.0.0-beta8-15964")
                .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            modelBuilder.Entity("PhoneSpotter.Models.PhoneSpotting", b =>
                {
                    b.Property<int>("PhoneSpottingId")
                        .ValueGeneratedOnAdd();

                    b.Property<double>("Latitude");

                    b.Property<double>("Longitude");

                    b.Property<string>("Notes");

                    b.Property<string>("PhoneManufacturer");

                    b.Property<string>("PhoneModel");

                    b.Property<DateTime>("SpotTime");

                    b.HasKey("PhoneSpottingId");
                });
        }
开发者ID:jeffa00,项目名称:WinPhoneSpotter2,代码行数:26,代码来源:PhoneSpottingDbContextModelSnapshot.cs


示例10: BuildTargetModel

        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "7.0.0-beta8-15964")
                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            modelBuilder.Entity("Dorothy.Models.Guest", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<int>("AdultCount");

                    b.Property<int>("ChildCount");

                    b.Property<string>("Group");

                    b.Property<bool>("HasEmail");

                    b.Property<bool>("HasInvitation");

                    b.Property<bool>("IsOptional");

                    b.Property<string>("Names");

                    b.Property<string>("Notes");

                    b.HasKey("Id");
                });
        }
开发者ID:saxx,项目名称:Project-Dorothy,代码行数:30,代码来源:20151026181902_HasEmail.Designer.cs


示例11: OnModelCreating

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     modelBuilder.Entity<Parent>()
         .HasMany(b => b.Children)
         .WithOne(b => b.MyParent)
         .HasForeignKey(b => b.ParentId);
 }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:7,代码来源:SqliteForeignKeyTest.cs


示例12: BuildModel

        protected override void BuildModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "1.0.1");

            modelBuilder.Entity("cloudscribe.Core.IdentityServer.EFCore.Entities.PersistedGrant", b =>
                {
                    b.Property<string>("Key");

                    b.Property<string>("Type");

                    b.Property<string>("ClientId")
                        .IsRequired()
                        .HasAnnotation("MaxLength", 200);

                    b.Property<DateTime>("CreationTime");

                    b.Property<string>("Data")
                        .IsRequired();

                    b.Property<DateTime>("Expiration");

                    b.Property<string>("SiteId")
                        .IsRequired()
                        .HasAnnotation("MaxLength", 36);

                    b.Property<string>("SubjectId");

                    b.HasKey("Key", "Type");

                    b.HasIndex("SiteId");

                    b.ToTable("csids_PersistedGrants");
                });
        }
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:35,代码来源:PersistedGrantDbContextModelSnapshot.cs


示例13: BuildModel

        protected override void BuildModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "1.0.0-rc2-20901");

            modelBuilder.Entity("LinkThere.Models.Link", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<int>("ClickCount")
                        .IsConcurrencyToken();

                    b.Property<string>("Key")
                        .IsRequired();

                    b.Property<string>("LinkUrl")
                        .IsRequired();

                    b.HasKey("Id");

                    b.HasIndex("Key")
                        .IsUnique();

                    b.ToTable("Links");
                });
        }
开发者ID:ddreier,项目名称:LinkThere,代码行数:27,代码来源:LinkThereContextModelSnapshot.cs


示例14: RegisterModels

        public void RegisterModels(ModelBuilder modelbuilder)
        {
            modelbuilder.Entity<Dictionary>(etb =>
            {
              etb.HasKey(e => e.Id);
              etb.Property(e => e.Id).UseSqlServerIdentityColumn();
              etb.ForSqlServerToTable("Dictionaries");
            }
              );

              modelbuilder.Entity<Culture>(etb =>
            {
              etb.HasKey(e => e.Id);
              etb.Property(e => e.Id).UseSqlServerIdentityColumn();
              etb.ForSqlServerToTable("Cultures");
            }
              );

              modelbuilder.Entity<Localization>(etb =>
            {
              etb.HasKey(e => e.Id);
              etb.Property(e => e.Id).UseSqlServerIdentityColumn();
              etb.ForSqlServerToTable("Localizations");
            }
              );
        }
开发者ID:rajendra1809,项目名称:Platformus,代码行数:26,代码来源:ModelRegistrar.cs


示例15: BuildTargetModel

        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "1.1.0-rtm-22752")
                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            modelBuilder.Entity("Domain.Bag", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("Description");

                    b.Property<string>("Factory");

                    b.Property<string>("ImageLink");

                    b.Property<string>("Name");

                    b.Property<string>("Owner");

                    b.Property<int>("Price");

                    b.Property<DateTime?>("TimeBought");

                    b.Property<DateTime>("TimeCreation");

                    b.HasKey("Id");

                    b.ToTable("Bags");
                });
        }
开发者ID:kostya9,项目名称:OP,代码行数:32,代码来源:20161125165403_Bags.Designer.cs


示例16: BuildModel

        protected override void BuildModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            modelBuilder.Entity("WebApi_Identity_Provider_DotNet.Models.Credential", b =>
                {
                    b.Property<string>("UserId")
                        .HasAnnotation("MaxLength", 256);

                    b.Property<string>("PublicKeyHash");

                    b.Property<string>("ActiveChallenge");

                    b.Property<string>("DeviceName")
                        .IsRequired();

                    b.Property<string>("PublicKey")
                        .IsRequired();

                    b.HasKey("UserId", "PublicKeyHash");

                    b.ToTable("Credentials");
                });
        }
开发者ID:FranceConnectSamples,项目名称:franceconnect-identity-provider-dotnet-webapi-aspnetcore,代码行数:26,代码来源:ApplicationDbContextModelSnapshot.cs


示例17: BuildTargetModel

        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "7.0.0-rc1-16348")
                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            modelBuilder.Entity("ASP.NET_Core_SPAs.Models.Contact", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("EmailAddress")
                        .HasAnnotation("MaxLength", 200);

                    b.Property<string>("Name")
                        .IsRequired()
                        .HasAnnotation("MaxLength", 200);

                    b.Property<string>("PhoneNumber");

                    b.Property<string>("UserId");

                    b.HasKey("Id");
                });
        }
开发者ID:elanderson,项目名称:ASP.NET-Core-SPAs,代码行数:25,代码来源:20160205214715_Init.Designer.cs


示例18: OnModelCreating

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().ToTable("Users");
            modelBuilder.Entity<User>().HasKey(c => c.UserId);
            modelBuilder.Entity<User>().Property(c => c.UserId).HasColumnName("Id");
            modelBuilder.Entity<User>().Property(x=> x.Identifier).HasColumnName("Login");
            modelBuilder.Entity<User>().Property(x=> x.Name).HasColumnName("Name");
            modelBuilder.Entity<User>().Property(x=> x.Email).HasColumnName("Email");
            modelBuilder.Entity<User>().Property(x=> x.IsSurveyor).HasColumnName("isSurveyor");
            modelBuilder.Entity<User>().Property(x=> x.Password).HasColumnName("Password");
            modelBuilder.Entity<User>().Property(x=> x.Status).HasColumnName("Status");

            // mappings for orgs...

            modelBuilder.Entity<Organization>().ToTable("Organizations");
            modelBuilder.Entity<Organization>().HasKey(x => x.OrganizationId);
            modelBuilder.Entity<Organization>().Property(x => x.OrganizationId).HasColumnName("ID");
            modelBuilder.Entity<Organization>().Property(x => x.Identifier).HasColumnName("Identifier");
            modelBuilder.Entity<Organization>().Property(x => x.Name).HasColumnName("Name");
            modelBuilder.Entity<Organization>().Property(x => x.Email).HasColumnName("Email");
            modelBuilder.Entity<Organization>().Property(x => x.BillingEmail).HasColumnName("BillingEmail");
            modelBuilder.Entity<Organization>().Property(x => x.CreatedAt).HasColumnName("FirstAdded");
            modelBuilder.Entity<Organization>().Property(x => x.Type).HasColumnName("Type");
            modelBuilder.Entity<Organization>().Ignore(x => x.Status);//.HasColumnName("Status");
        }
开发者ID:hahmed,项目名称:TeamKudu,代码行数:25,代码来源:DbContext.cs


示例19: OnModelCreating

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //Ignores
            modelBuilder.Ignore<DataPoint>();
            modelBuilder.Ignore<MarketsAndNews>();
            modelBuilder.Ignore<MarketQuotes>();
            modelBuilder.Ignore<OperationStatus>();
            modelBuilder.Ignore<TickerQuote>();
            modelBuilder.Ignore<Security>();

            // Map these class names to the table names in the DB for Table Per Type (TPT)
            // Currently not supported in EF7

            //modelBuilder.Entity<Security>().ToTable("Security");
            //modelBuilder.Entity<Stock>().ToTable("Stock");
            //modelBuilder.Entity<MutualFund>().ToTable("MutualFund");

            //Create one to many relationship between Customer/BrokerageAccounts
            //modelBuilder.Entity<Customer>()
            //    .Collection(c => c.BrokerageAccounts)
            //    .InverseReference(ba => ba.Customer)
            //    .ForeignKey(ba => ba.CustomerId);

            //modelBuilder.Entity<BrokerageAccount>()
            //    .Collection(ba => ba.Positions)
            //    .InverseReference(p => p.BrokerageAccount)
            //    .ForeignKey(p => p.BrokerageAccountId);
        }
开发者ID:obryckim,项目名称:AccountAtAGlance2015,代码行数:28,代码来源:AccountAtAGlanceContext.cs


示例20: BuildTargetModel

        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "1.0.0-rc2-20901")
                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

            modelBuilder.Entity("Haufwerk.Models.Issue", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("AdditionalInfo");

                    b.Property<DateTime>("CreationDateTime");

                    b.Property<bool>("Ignore");

                    b.Property<string>("Message");

                    b.Property<Guid?>("ParentId");

                    b.Property<string>("Source");

                    b.Property<string>("StackTrace");

                    b.Property<string>("User");

                    b.HasKey("Id");

                    b.ToTable("Issues");
                });
        }
开发者ID:saxx,项目名称:Haufwerk,代码行数:32,代码来源:20160607071118_Initial.Designer.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ModelClassFactory类代码示例发布时间:2022-05-24
下一篇:
C# ModelBindingExecutionContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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