I'd like to know if the next problem can be solved in a different way in NHibernate.
Let's say we've this domain:
public class A
{
public virtual B LastAssociationWithB { get; set; }
public virtual ICollection<B> CollectionAssociationOfB { get; set; }
}
public class B
{
public virtual DateTime DateAdded { get; set; }
}
The LastAssociationWithB
property represents one of the B
persistent objects associated in the CollectionAssociationOfB
collection property.
Actually, LastAssociationWithB
represents the last B
persistent object added by date.
So, in the domain, when a new B
is added to CollectionAssociationOfB
, it's also assigned to LastAssociationWithB
.
This is a good way of later turning code into less complex LINQ queries.
Anyway, my question is: do you know any other approach to this? For example, some kind of many-to-one association that produces a SQL join under the hoods so you wouldn't need to have an explicit 1:n relation in the A
table but it would maintain the class property?
Or is my current approach the recommended way of solving this scenario?
Side note: in the real-world scenario that CollectionAssociationOfB
is an ordered list as ordering is specified in the NHibernate mapping configuration.