Question

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.

Was it helpful?

Solution

Instead of IEnumerable<Contact> use ICollection<Contact> (for bag semantics) or ISet<Contact> (for set semantics) or IList<Contact>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top