How to fluent-map this?

2 views
Skip to first unread message

sk

unread,
Nov 6, 2009, 11:26:40 AM11/6/09
to Fluent NHibernate
Hello,

I have two tables in my database "Styles" and "BannedStyles". They
have a reference via the ItemNo. Now styles can be banned per store.
So if style x is banned at store Y then its very possible that its not
banned at store Z or vice verse. What is the best way now to map this
to a single entity? Should I be mapping this to a single entity?

My Style entity looks like this:

public class Style
{
public virtual int ItemNo { get; set;}
public virtual string SKU { get; set; }
public virtual string StyleName { get; set; }
public virtual string Description { get; set; }
public virtual Store Store { get; set; }
public virtual bool IsEntireStyleBanned { get; set; }
}

Hudson Akridge

unread,
Nov 6, 2009, 11:31:25 AM11/6/09
to fluent-n...@googlegroups.com
Not to a single entity, you need essentially a matrix for you to process those. So in data terms, it would be a separate table. In NH/FNH terms, it means creating a StyleStatus class, or something like that.

StyleStatus will have a References() (or Many-To-One in NH terms) to Style, and also have a References() to the Store. Style and Store will have a HasMany() (one-to-many) to StyleStatus.

StyleStatus can contain various bits of information, one of which could be the boolean you've got on the Style class right now IsEntireStyleBanned. Style shouldn't need a reference to store, it's technically got a Many to Many association to Store, but because the MTM reference needs to store an additional attribute (IsEntireStyleBanned) it needs to be represented in NH as a class.

Let me know if that makes sense for you :)

sk

unread,
Nov 6, 2009, 11:55:16 AM11/6/09
to Fluent NHibernate
Got ya. Now would I create a physical StyleStatus table as well?

sk

unread,
Nov 6, 2009, 12:04:56 PM11/6/09
to Fluent NHibernate
I just saw that you already answered that :)

Thanks,

sk

unread,
Nov 9, 2009, 8:17:38 AM11/9/09
to Fluent NHibernate
Followup question: How would I use mapping and Linq if the tables are
in different databases?
In the above example, the "Store" table is in database X and
"StyleStatus" and "Styles" are in database Y.

Thanks,
Reply all
Reply to author
Forward
0 new messages