Castle ActiveRecord 关系
我正在尝试将以下模型与 Castle ActiveRecord
- Contact(由姓名和电话号码代表的人)映射。
- 组(代表一组联系人)。
联系人可以属于多个不同的组,但不必位于一个组中。
在数据库中,我表示为:
联系人
- ID
- 姓名
- 电话号码
组
- ID
- GroupName
Group_Contact - 组ID - ContactId
联系人不需要知道它属于哪些组(也许这是映射需求,但不是业务需求)。
理想情况下,我只想在 Group 类上有一个联系人集合。
我尝试在 Group 类中像这样映射它,
[HasAndBelongsToMany(typeof(Contact),
Table = "Group_Contact", ColumnKey = "GroupId", ColumnRef = "ContactId")]
public IEnumerable<Contact> Contacts { get; set; }
这给了我以下异常: 无法猜测属性 Group.Contacts 的关系类型
非常感谢任何帮助。
I'm trying to map the following model with Castle ActiveRecord
- Contact (a person represented by a name and a phone number).
- Group (represents a group of contacts).
A contact can belong to several different groups, but does not have to be in a group.
In the database this i represented as:
Contact
- Id
- Name
- PhoneNumber
Group
- Id
- GroupName
Group_Contact
- GroupId
- ContactId
The contact does not need to know which groups it is contained by (maybe it's a mapping requirement, but not a business requirement).
Ideally I'd like to just have a collection of Contacts on the Group class.
I've tried mapping it like this in the Group class
[HasAndBelongsToMany(typeof(Contact),
Table = "Group_Contact", ColumnKey = "GroupId", ColumnRef = "ContactId")]
public IEnumerable<Contact> Contacts { get; set; }
Which gives me the following exception:
Could not guess relation type for property Group.Contacts
Any help is highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ICollection
(对于包语义)或ISet
(对于集合语义)或IEnumerable
来代替IEnumerable
>IList<联系人>Instead of
IEnumerable<Contact>
useICollection<Contact>
(for bag semantics) orISet<Contact>
(for set semantics) orIList<Contact>