Hi, my application has the following entity:
public class User
{
public virtual int UserID { get; set; }
public virtual Membership LatestMembership { get { return Membership.First(); } }
public virtual IList<Membership> Membership { get; set; }
public User()
{
Membership = new List<Membership>();
}
}
With the following mapping:
public UserMap()
{
Table("Users");
Id(x => x.UserID);
HasMany(x => x.Membership)
.KeyColumn("UserID")
.OrderBy("DateAdded DESC")
.Inverse()
.Cascade.All();
}
The LatestMembership property against the user simply grabs the first record from the Membership collection (which is ordered so that the newer records are at the top).
So far so good, however now say i want to do the following (i know this will return them all but i'm just using this as an example):
var users = session.Linq<User>()
.Where(u => u.LatestMembership.DateAdded < DateTime.UtcNow);
An error is thrown because the LatestMembership property is beyond the nhibernate linq providers capabilities. The only solution i have so far is to convert it to a list and then apply the where condition but i'd imagine this could become pretty insuficient for a large database.
I was wondering if there was an alternative way i could map this or what your recommendations are. Thanks