Yes - basically that Idea. I am currently using the the SelfServicing templates ('Two class scenario') and achieving a similar thing by overriding the Collection Properties from the EntityBase.
However, if there was a "ConcurrencyPredicateFactoryToUse" type of setup, it would allow for the setting or overriding of this behaviour on the fly. Perhaps each relation could have its own predicateExpression property, and if it was not null, it would be used as a filter on the Collection retrieval. This way, it would be possible to set up the entity to initialise with default filter behaviours. Maybe the Property could be something like the following:
public virtual CollectionClasses.OrdersCollection Orders
{
get
{
CollectionClasses.OrdersCollection OrdersCollection = null;
//get collection
if(this.FetchOrderPredicateExpressionToUse != null)
{
OrdersCollection = GetMultiOrders(false, this.FetchOrderPredicateExpressionToUse);
}
else
{
OrdersCollection = GetMultiOrders(false);
}
return OrdersCollection;
}
}
If this was combined with an TDL "EntityFieldExist" tag, it would be possible to write code in the include templates that would automatically register filter predicates when certain fields exist (such as "Deleted"). It could be CodeGen heaven!
If may also be useful if this could be extended to the EntityInstantiation. Perhaps a property on each Entity "FetchPredicateExpressionToUse" could automatically apply a filter on the instantiation. EG:
/// <summary>
/// CTor
/// </summary>
/// <param name="pkId">PK value for Orders which data should be fetched into this Orders object</param>
public OrdersEntityBase(System.Int64 pkId)
{
if(this.FetchPredicateExpressionToUse != null)
{
InitClassFetch(pkId, new OrdersValidator(), new PropertyDescriptorFactory(), new OrdersEntityFactory(), null, this.FetchPredicateExpressionToUse);
}
else
{
InitClassFetch(pkId, new OrdersValidator(), new PropertyDescriptorFactory(), new OrdersEntityFactory(), null);
}
}
Here is a quick example of where i see this as being useful, so you can see where i am coming from:
When items (such as orders) are "deleted", they are often needed for future reporting purposes, as so are not really deleted, but a "Deleted" field is marked as true in the database. One of the problems I have found with this is that allot of extra filter code is required, and that developers (including myself) are prone to forget to filter out the deleted items. With features such as the above suggested, it would be possible to set up the entities so that by default they would not return any item where the deleted field was true. This would be a great time saver, and also make for more consistent and robust software.
You may know of many good reasons why all of the above is either not practical or sensible - in which case ignore this!