hoping this is an easy one for you veterans:
Parent Class (Asset) with a Collection of Children (MemberAssets). Child class is an association class if that matters. I'm tryig to use ICriteria to find an IList of Assets with certain properties, one of them being a MemberAssets collection that is not empty. I though this might work:
Code:
public IList GetOwnedAssets(Member owner, bool isArchived, string orderByField)
{
return this.dbSession.CreateCriteria(typeof(Asset))
.Add(Expression.Eq("Owner", owner))
.Add(Expression.Eq("IsArchived", isArchived))
.Add(Expression.IsNotNull("MemberAssets"))
.AddOrder(Order.Asc(orderByField))
.List();
}
but it doesn't. This makes sense actually because my constructor(s) initialized the array:
Code:
protected Asset()
{
this.id = new Guid("00000000-0000-0000-0000-000000000000");
this.version = -1;
this.dateCreated = DateTime.Now;
this.lastUpdate = DateTime.Now;
this.memberAssets = new ArrayList();
}
protected Asset(string title, Member owner)
{
this.id = new Guid("00000000-0000-0000-0000-000000000000");
this.version = -1;
this.title = title;
this.owner = owner;
this.dateCreated = DateTime.Now;
this.lastUpdate = DateTime.Now;
this.memberAssets = new ArrayList();
}
I could remove the assignment from the constructor but would still need it in the property:
Code:
public virtual IList MemberAssets
{
get
{
if (this.memberAssets == null)
this.memberAssets = new ArrayList();
return this.MemberAssets;
}
}
so either way MemberAssets is never going to be NULL. Is there any to do this using ICriteria? Essentially, I think I'm trying to check the MemberAssets.Count property in the query...
Thanks in advance,
-devon