码迷,mamicode.com
首页 > 其他好文 > 详细

EF有外键的查询

时间:2015-06-15 18:25:10      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

            modelBuilder.Entity<ActionMenu>().ToTable("ActionMenu");
            modelBuilder.Entity<ActionMenu>().HasKey(s => s.Id);
            modelBuilder.Entity<ActionMenu>().Property(s => s.MenuName).IsRequired().HasMaxLength(50);


            modelBuilder.Entity<ActionMenu>().HasMany(t => t.ChildActions)
                .WithMany()
                .Map(m =>
                {
                    m.ToTable("ActionMenu_ActionInfo_Mapping");
                    m.MapLeftKey("ActionMenuId");
                    m.MapRightKey("ActionInfoId");
                });

            modelBuilder.Entity<ActionMenu>().HasOptional(p => p.Parent).WithMany(p => p.ChildKeys);


            modelBuilder.Entity<ErpMember>().ToTable("ErpMember");
            modelBuilder.Entity<ErpMember>().HasKey(s => s.Id);
            modelBuilder.Entity<ErpMember>().Property(s => s.Email).IsRequired().HasMaxLength(50);
            modelBuilder.Entity<ErpMember>().Property(s => s.Moblie).IsRequired().HasMaxLength(20);
            modelBuilder.Entity<ErpMember>().Property(s => s.PassWord).IsRequired().HasMaxLength(50);
            modelBuilder.Entity<ErpMember>().Property(s => s.UserName).IsRequired().HasMaxLength(50);
            modelBuilder.Entity<ErpMember>().Property(s => s.LastIpAddress).HasMaxLength(20);

            //modelBuilder.Entity<ErpMember>().HasMany(b => b.ChildKeys).WithRequired(p => p.Parent);
            modelBuilder.Entity<ErpMember>().HasOptional(p => p.Parent).WithMany(p => p.ChildKeys);

            modelBuilder.Entity<BillLoanApply>().ToTable("BillLoanApply");
            modelBuilder.Entity<BillLoanApplyDetail>().ToTable("BillLoanApplyDetail");
            modelBuilder.Entity<BillRepayment>().ToTable("BillRepayment");
            modelBuilder.Entity<DictEnum>().ToTable("DictEnum");
            modelBuilder.Entity<MapSignInTask>().ToTable("MapSignInTask");


            // BillLoanApply 贷款申请表
            modelBuilder.Entity<BillLoanApply>().ToTable("BillLoanApply");
            modelBuilder.Entity<BillLoanApply>().HasKey(b => b.Id);

 

EF有外键的查询

标签:

原文地址:http://www.cnblogs.com/honghong75042/p/4578803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!