0

假设一个人可以属于多个组,一个组可以包含多个人。
一个人也可以管理几个组,一个组可以由几个人管理。

如何向这些属性添加一些属性(InverseProperty),以便它们彼此正确匹配?

public class Person
{
   public virtual ICollection<Group> Groups { get; set; }
   public virtual ICollection<Group> AdministratedGroups { get; set; }
}

public class Group
{
   public virtual ICollection<Person> Members { get; set; }
   public virtual ICollection<Person> Administrators { get; set; }
}

谢谢

4

1 回答 1

0

好吧,最后很明显:

public class Person
{
   [InverseProperty("Members")]
   public virtual ICollection<Group> Groups { get; set; }
   [InverseProperty("Administrators")]
   public virtual ICollection<Group> AdministratedGroups { get; set; }
}

public class Group
{
   [InverseProperty("Groups")]
   public virtual ICollection<Person> Members { get; set; }
   [InverseProperty("AdministratedGroups")]
   public virtual ICollection<Person> Administrators { get; set; }
}
于 2013-03-21T22:42:27.890 回答