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


C# DbModelBuilder.SetUniqueField方法代码示例

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


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

示例1: OnModelCreating

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

            modelBuilder.SetUniqueField<Place>(x => x.Name, 250, "idx_place_name", 1);
            modelBuilder.Entity<Place>().Property(x => x.Name).IsRequired();
            //modelBuilder.SetUniqueField<Desk>(x => x.Name, 250, "idx_desk_name", 1);

            /*modelBuilder.SetUniqueField<Producer>(x => x.Name, 250, "idx_producer_name", 1);
                modelBuilder.SetUniqueField<Supplier>(x => x.Name, 250, "idx_supplier_name", 1);
                modelBuilder.SetUniqueField<Customer>(x => x.Name, 250, "idx_customer_name", 1);
                // packing
                modelBuilder.Entity<Packing>().Property(x => x.Name).HasMaxLength(250).IsRequired();
                modelBuilder.Entity<Packing>().Property(x => x.ItemsCount).IsRequired();
                modelBuilder.Entity<Packing>().Property(x => x.Reusable).IsRequired();
                modelBuilder.Entity<Packing>().HasRequired(x => x.MeasureUnit);
                // products
                modelBuilder.Entity<Product>().HasRequired(x => x.MeasureUnit);
                modelBuilder.Entity<Product>().Property(x => x.Name).HasMaxLength(250).IsRequired();
                modelBuilder.Entity<Product>().Property(x => x.Price).IsRequired();
                // measure units
                modelBuilder.SetUniqueField<MeasureUnit>(x => x.FullName, 250, "idx_measureunit_name", 1);
                modelBuilder.Entity<MeasureUnit>().Property(x => x.ShortName).IsRequired();
                // invoices
                modelBuilder.Entity<Model.Invoice>().HasRequired(x => x.Customer);
                modelBuilder.Entity<Model.Invoice>().HasRequired(x => x.Supplier);
                modelBuilder.Entity<Model.Invoice>().HasRequired(x => x.Producer);
                modelBuilder.Entity<Model.Invoice>().Property(x => x.Date).IsRequired();
                // invoice items
                modelBuilder.Entity<InvoiceItem>().HasRequired(x => x.Product);
                modelBuilder.Entity<InvoiceItem>().Property(x => x.Count).IsRequired();*/
        }
开发者ID:qrunner,项目名称:Default,代码行数:32,代码来源:Context.cs

示例2: OnModelCreating

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

            // Measure Units
            modelBuilder.Entity<MeasureUnit>().HasKey<int>(x => x.Id);
            modelBuilder.SetUniqueField<MeasureUnit>(x => x.Name, 128, "idx_MU_name", 1);
            modelBuilder.SetUniqueField<MeasureUnit>(x => x.ShortName, 8, "idx_MU_shortname", 2);

            // Unit Categories
            modelBuilder.Entity<UnitCategory>().HasKey<int>(x => x.Id);
            modelBuilder.Entity<UnitCategory>().HasMany<UnitCategory>(x => x.ChildItems);

            // Units
            modelBuilder.Entity<Unit>().HasKey<int>(x => x.Id);
            modelBuilder.SetUniqueField<Unit>(x => x.Name, 250, "idx_Unit_name", 1);

               // modelBuilder.Entity<RecipeUnitCount>().HasKey(t => new {t.UnitId, t.RecipeId});

            modelBuilder.Entity<Document>().Ignore(x => x.Name);

            //modelBuilder.Entity<DocumentType>().Ignore(x => x.SiteIds);
        }
开发者ID:qrunner,项目名称:Default,代码行数:23,代码来源:Context.cs


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