csharp 表间关系

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 表间关系相关的知识,希望对你有一定的参考价值。

modelBuilder.Entity<BlogSite>()
    .HasRequired(b => b.BlogUser)
    .WithMany()
    .HasForeignKey(b => b.UserID);

modelBuilder.Entity<BlogUser>()
    .HasRequired(u => u.BlogSite)
    .WithMany()
    .HasForeignKey(u => u.BlogID);
    
    
  /////////////////////////////
  public class User 
  {     
    public int UserId { get; set; }     
    public string Name { get; set; }     
    public int BillingAddressId { get; set; }    
    public int DeliveryAddressId { get; set; }     
    [ForeignKey("BillingAddressId")]     
    public Address BillingAddress { get; set; }     
    [ForeignKey("DeliveryAddressId")]     
    public Address DeliveryAddress { get; set; } 
  }
modelBuilder.Entity<BlogSite>()
    .HasRequired(b => b.BlogUser)
    .WithMany()
    .HasForeignKey(b => b.UserID).WillCascadeOnDelete(false);;
    
   
modelBuilder.Entity<BlogSite>()
    .HasMany(b => b.BlogPosts)
    .WithRequired(p => p.BlogSite);
modelBuilder.Entity<BlogPost>()
    .HasMany(b => b.Categories)
    .WithMany(c => c.BlogPosts)
    .Map
    (
        m =>
        {
            m.MapLeftKey("BlogPostID");
            m.MapRightKey("CategoryID");
            m.ToTable("BlogPost_Category");
        }
    );

以上是关于csharp 表间关系的主要内容,如果未能解决你的问题,请参考以下文章

表间关系设计建议

Node.js ORM框架Sequlize之表间关系

EF简易教程,从建表到表间关系

SQL SERVER中获取表间主外键关系

mysql 数据库表间关系图怎么查看啊?

mysql 数据库表间关系图怎么查看?