Hi Lauri,
Ok. I suggested DynamicList because it would make a little more efficient the query (you just retrieve the count of children, no the children per-se).
Now, if you want to use EntityCollections you have two options:
A. Write a simple property on your ParentEntity. You can do this in a partial class or on the CUSTOM_USER_CODE_REGIONS on the ParentEnttiy.cs file. The property could look like:
public int NumerOfAdults
{
get
{
return this.Children.Count;
}
}
Please note that this property only count the already objects in your parent. That means that, if you are Adapter you must prefetch the Children right? If you are using SelfServicing this would work without prefethpath but in this case I would recommend you use them for performance.
If you want to filter the count and you are using prefetchpaths (needed in the case of Adapter) you can actually filter the prefetchPath, so you wont filter in-memory.
Now, it could be that you don't want to filter on prefetchpaths because you need different filters depending on the property (a property that shows adults, other that shows kids). You can use EntityViews to filter the children collection. For example (assuming you are using Adapter, but it pretty the same for SelfServicing):
public int NumerOfAdults
{
get
{
EntityView2<ChildEntity> childrenView = new EntityView2<ChildEntity>(this.Children);
IPredicate filter = (ChildFields.Age > 21);
childrenView.Filter = filter;
return childrenView.Count;
}
}
The same if for other properties you want to create. If you are using .NET3.5 you can simplify the in-memory filter.
Now you can use those properties on your databinding control.
B. The other option is that you don't need to fetch the children, you just create additional fields expression that query the counts (similar to DynamicList, but working on EntityCollections). For more information please take a look at this article (Step 6): http://weblogs.asp.net/fbouma/archive/2006/06/09/LLBLGen-Pro-v2.0-with-ASP.NET-2.0.aspx
Hope helpful