So, I have two tables, call them User and Item. I want each user to be able to flag (like “staring” things in the Google universe) any item.
Now, from a set-theoretic perspective it should be reasonable to store this as a simple relation between users and items. Call this new table UserItemFlags. The table should have two columns; one with foreign keys to the User table, the other with foreign keys to the Item table. If user U flags item I, this is then represented by the presence of the row (U, I) in the UserItemFlags table.
Now, my problem with expressing this in Fluent-NHibernate is this: I can’t seem to understand what to do with the Id mapping. Ideally, I would have no ID, because there is nothing more to it than presence or absence of this relation between a User and an Item. A natural consequence of this model is that it’s impossible to have duplicate rows in the table. This is a desired feature.
using FluentNHibernate.Mapping;
public class UserItemFlagsMapping : ClassMap<UserItemFlags>
{
public UserItemFlagsMapping()
{
// Aaaa! I must have an Id!
References(x => x.User).Not.Nullable();
References(x => x.Item).Not.Nullable();
}
}
I’d be happy for any pointers in the right direction, even if they would require me to abandon Fluent for this specific case.
What do you mean you don’t have an ID? You have a composite ID right there of both user ID and item ID.
Edit: The answer is in this comment: