entityframwork_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > entityframwork

entityframwork

 2013/8/8 16:12:09  zhishuru  博客园  我要评论(0)
  • 摘要:entityframwork映射部分:publicclassNorthwindContext:DbContext{publicDbSet<CATEGORIES>Categories{get;set;}publicDbSet<CUSTOMERS>Customers{get;set;}publicDbSet<EMPLOYEES>Employees{get;set;}publicDbSet<PRODUCTS>Products{get;set;
  • 标签:

entityframwork映射部分:

class="brush:csharp;gutter:false;">  public class NorthwindContext : DbContext
    {


      

        public DbSet<CATEGORIES> Categories { get; set; }
        public DbSet<CUSTOMERS> Customers { get; set; }
        public DbSet<EMPLOYEES> Employees { get; set; }
        public DbSet<PRODUCTS> Products { get; set; }
        public DbSet<ORDERS> Orders { get; set; }
        public DbSet<SUPPLIERS> Suppliers { get; set; }
        public DbSet<SHIPPERS> Shippers { get; set; }
        public DbSet<ORDER_DETAILS> Order_Details { get; set; }
       

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            modelBuilder.Entity<CATEGORIES>().ToTable("CATEGORIES", "TEMP");
            modelBuilder.Entity<CUSTOMERS>().ToTable("CUSTOMERS", "TEMP");
            modelBuilder.Entity<EMPLOYEES>().ToTable("EMPLOYEES", "TEMP");
            modelBuilder.Entity<PRODUCTS>().ToTable("PRODUCTS", "TEMP");
            modelBuilder.Entity<ORDERS>().ToTable("ORDERS", "TEMP");
            modelBuilder.Entity<SUPPLIERS>().ToTable("SUPPLIERS", "TEMP");
            modelBuilder.Entity<SHIPPERS>().ToTable("SHIPPERS", "TEMP");
            modelBuilder.Entity<ORDER_DETAILS>().ToTable("ORDER_DETAILS", "TEMP");
            

         
            modelBuilder.Entity<SUPPLIERS>().HasMany(b => b.Products1).WithRequired(a => a.SUPPLIERS1);
            modelBuilder.Entity<EMPLOYEES>().HasMany(b => b.Employees1).WithRequired(a => a.Employees2);
            modelBuilder.Entity<CUSTOMERS>().HasMany(b => b.Orders).WithRequired(a => a.Customers);
            modelBuilder.Entity<EMPLOYEES>().HasMany(b => b.Orders).WithRequired(a => a.Employees);
            modelBuilder.Entity<CATEGORIES>().HasMany(b => b.Products).WithRequired(a => a.CATEGORIES);
            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.ColumnTypeCasingConvention>();


       
       
            base.OnModelCreating(modelBuilder);
        }
    }

  

上一篇: 没有人知道我们正在做什么 下一篇: 没有下一篇了!
  • 相关文章
发表评论
用户名: 匿名