Problem with a custom predicate

Posts   
 
    
studiosoft
User
Posts: 15
Joined: 25-May-2005
# Posted on: 04-Mar-2008 20:36:54   

I'm developing a custom predicate inherited from the Predicate class. The goal is surround the output text of a given predicate with a Not clause. Ej: "Not ({FieldComparePredicate})" But the code, throw an NullReference exception when ToQueryText is called from the internal predicate.

Here is the code:

Imports SD.LLBLGen.Pro.ORMSupportClasses

Public Class NotPredicate
    Inherits Predicate

    Private m_SourcePredicate As Predicate

    Public Sub New(ByVal predicate As Predicate)
        MyBase.New()
        Me.m_SourcePredicate = predicate
    End Sub

    Public Overloads Overrides Function ToQueryText(ByRef uniqueMarker As Integer) As String
        Return ToQueryText(uniqueMarker, False)
    End Function

    Public Overloads Overrides Function ToQueryText(ByRef uniqueMarker As Integer, ByVal inHavingClause As Boolean) As String
            Me.m_SourcePredicate.DatabaseSpecificCreator = Me.DatabaseSpecificCreator
            Return String.Format("NOT ({0})", Me.m_SourcePredicate.ToQueryText(uniqueMarker, inHavingClause))

    End Function

End Class

Stack Trace:


    ex.StackTrace   "   at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateParameter(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, ParameterDirection direction, Object valueToSet)
   at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at Studio.Net.BLL.NotPredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) in C:\personal\Studio\Net\BLL\LLBLGen\NotPredicate.vb:line 20"   String

The runtime version is 2.0.0.0 (March 21st, 2007)

Any help will be welcome, thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Mar-2008 10:58:13   

Are you using SelfServicing or the Adapter model?

Anyway you don't have to create your own predicate to negate a FieldCompareValuePredicate.

Please check Negative predicates in the LLBLGen Pro manual's section "Using the generated code -> Adapter/SelfServicing -> Filtering and sorting -> Advanced filter usage"

studiosoft
User
Posts: 15
Joined: 25-May-2005
# Posted on: 05-Mar-2008 18:49:09   

I'm using adapter model.

I'm trying to translate a DevExpress criteria to a LLBLGenPro predicate, so i need to do it in that way. Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Mar-2008 23:28:45   
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 06-Mar-2008 10:29:55   

All predicates support 'NOT'. It's in the IPredicate interface: ((IPredicate)somePredicate).Negate = true;

now the 'somePredicate' is negated in the output in the way it fits the predicate. If somePredicate is a predicateExpression, the whole predicate expression is negated: NOT (predicateExpression)

Frans Bouma | Lead developer LLBLGen Pro
studiosoft
User
Posts: 15
Joined: 25-May-2005
# Posted on: 06-Mar-2008 15:24:26   

Thanks Frans !!! This what exactly i need. sunglasses