IPredicateExpression - always FALSE.

Posts   
 
    
griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 24-Apr-2009 07:10:28   

Hi. I need something like this

MyFilter.PredicateExpression.AddWithAnd(false);

With this filter any EntityCollection will be empty.

P.S. Sorry for my english,

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Apr-2009 10:34:08   

Use a filter which will always return false, like PK == -1.

griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 24-Apr-2009 10:55:22   

Walaa wrote:

Use a filter which will always return false, like PK == -1.

Thank you, but I want to use filter to fetch ANY kind of entity.

griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 24-Apr-2009 10:59:01   

For example, i have OrganizationEntity and CustomerEntity. I need 1 RelationPredicateBucket object for these types.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Apr-2009 11:08:30   

Drive your own Predicate from any of the available FieldPredicates and override ToQueryText() to produce the sql that your want.

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 24-Apr-2009 12:20:15   

Does this help?

[Serializable]
    public class MatchNonePredicate: Predicate
    {
        public static readonly MatchNonePredicate Instance = new MatchNonePredicate();

        MatchNonePredicate() { }

        protected override bool InterpretPredicate(IEntityCore entity) { return false; }

        public override string ToQueryText(ref int uniqueMarker) { return "(0=1)"; }

        public override string ToQueryText(ref int uniqueMarker, bool inHavingClause) { return "(0=1)"; }
    }

Cheers Simon

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 24-Apr-2009 12:40:00   

Just out of interest - why would you want to run a query to return no entities ?

The usual reason for doing this with a datatable is to get the column names but no data, but if this is the case you can just create a new entity...

Matt

griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 06-May-2009 13:10:07   

simmotech wrote:

Does this help?

Thank you. This is what I needed.

griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 06-May-2009 13:14:00   

MTrinder wrote:

Just out of interest - why would you want to run a query to return no entities ?

The usual reason for doing this with a datatable is to get the column names but no data, but if this is the case you can just create a new entity...

Matt

We have a web site with a searh page. The Request parameters are analyzed on this page and if the parameters are incorrect the results of the request will be empty. At searh page there are several UserControls which take RelationPredicateBucket as a property. And my search page returns MatchNonePredicate for these controls in that case.