0
我如何去从一个表(帐户)配置一个一对多的关系,两个表评论和张贴之一,从一个表中的许多多个表
public class Account
{
public int AccountID { get; set; }
[Required(ErrorMessage = "Please enter a username")]
[Display(Name = "Username")]
public string Username { get; set; }
public string userid { get; set; }
[Required(ErrorMessage = "Please enter the password")]
[Display(Name = "Password")]
public string Password { get; set; }
public ICollection<Post> Posts { get; set; }
public ICollection<Comment> Comments { get; set; }
}
public class Post
{
public int PostId { get; set; }
[Required]
public string Heading { get; set; }
[Required]
public string PostText { get; set; }
public virtual Account Account {get;set;}
public ICollection<Comment> Comments { get; set; }
}
public class Post
{
public int PostId { get; set; }
[Required]
public string Heading { get; set; }
[Required]
public string PostText { get; set; }
public virtual Account Account {get;set;}
public ICollection<Comment> Comments { get; set; }
}
以下是我的流畅API
modelBuilder.Entity<BusinessObjects.Account>().HasMany(a => a.Posts).WithRequired().Map(m => m.MapKey("AccountId"));
modelBuilder.Entity<BusinessObjects.Account>().HasMany(a => a.Comments).WithRequired().Map(m => m.MapKey("AccountId"));
modelBuilder.Entity<BusinessObjects.Post>().HasMany(p => p.Comments).WithRequired().Map(m => m.MapKey("Postid"));
以下是错误我得到:
引进国外KEY约束 “FK_dbo.Posts_dbo.Accounts_表'帖子'上的AccountId'可能导致 周期或多个级联路径。指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。不能 创建约束
我想我的流利api帐户 - >发布可能不正确,任何人都可以提出解决方案吗?
我编辑了你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2014-09-23 22:53:04