In Fluent NHibernate, how would I map the following domain models?

Posted by Brandon on Stack Overflow See other posts from Stack Overflow or by Brandon
Published on 2010-06-17T01:50:24Z Indexed on 2010/06/17 1:52 UTC
Read the original article Hit count: 269

Filed under:
|

I have a user class that looks something like this

public class User
{
    public virtual int Id { get; set; }

    public virtual long ValueA { get; set; }

    public virtual int? ValueB { get; set; }
}

ValueA is automatically assigned by the system. It is used in a lookup that would map to UserClass. However, if a value for ValueB exists, then it would do the lookup for UserClass in a different way.

Right now the way I handle it is to get the User and then perform a separate lookup each time.

return user.ValueB.HasValue ? Find(user.ValueB.Value) : Find(user.ValueA);

Is there any way to make Fluent NHibernate do this for me so I can have UserClass as a property on the User class instead of having to do the lookup separately? I was thinking of the ComponentMap but I'm not sure how to make it account for the two possible lookup values.

© Stack Overflow or respective owner

Related posts about c#

Related posts about fluent-nhibernate