Using custom Business Logic fields in Predicates

Posts   
 
    
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 18-Jul-2008 01:10:24   

I have been using .NET partial class defintions to add custom fields to entities.

For example, i have a Folder entity and a Document entity. The folder has a collection of documents. In my business layer i have defined a partial class for the folder and added to it a property called LastDocumentDate to provide to the Folder entity the date of the most recent Document in its Documents collecttion.

Is there any way to set up a filter on the property i added in the partial class definiton (i.e. not in the designer)?

I want to find all folders where the LastDocumentDate < today for example.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Jul-2008 05:27:01   

Hi nilsey,

As it's a custom property that doesn't exist at DB (f.i: your Folder table doesn't contain such LastDocumentDate field) the best way is to find it in-memory. It that is ok, you could use _EntityProperty _to add predicates to your filter:

filter.AddWithAnd(new EntityProperty("LastDocumentDate") < someDateValue);

For more info about in-memory filtering, read this documentation section.

If I understand well your scenario, that should be sufficient. However if you want some more(f.i: filter at fetch-time), please let us know.

David Elizondo | LLBLGen Support Team
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 18-Jul-2008 07:14:11   

yeah i was hoping to filter the entities using that property when they are fetched rather than after i ahve retrieved a collection.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 18-Jul-2008 10:55:23   

That's an in memory filtering, maybe you want to formulate a SQL query to filter on the database side rather than in memory.

nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 06-Aug-2008 02:20:58   

Walaa wrote:

That's an in memory filtering, maybe you want to formulate a SQL query to filter on the database side rather than in memory.

Um, is there a section in the documentation you could point me to that deals with custom filtering of entities? is there some way to inject SQL and make your filter explicit that way?

or are you suggesting i write some new stored proc or view in the DB and wrap that ina new entity or typed list?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 10:40:48   

If the filtering can indeed be carried out in the database, would you please post a sample SQL Query of what you are trying to do.

Then we can tell you how to approach it using LLBLGen Pro code.