Add If condition in PredicateExpression & conditiion on PrefatchPath table

Posts   
 
    
Posts: 19
Joined: 11-Jan-2010
# Posted on: 10-Feb-2010 18:40:16   

Hello everybody,

Could please somebody help me out with two my problems or recommend me the best way to get around them.

I have the following code:

Dim ewi As New EntityCollection(Of EquipmentWorkItemEntity) Dim pfp As IPrefetchPath2 = New PrefetchPath2(CInt (EntityType.EquipmentWorkItemEntity)) pfp.Add(EquipmentWorkItemEntity.PrefetchPathWorkItem) pfp.Add(EquipmentWorkItemEntity.PrefetchPathRecurrance)

  Dim filter As IRelationPredicateBucket = New RelationPredicateBucket

  filter.PredicateExpression.Add(New FieldCompareNullPredicate(RecurranceFields.NotifyDaysPrior, Nothing, True))

  filter.PredicateExpression.Add(New FieldCompareNullPredicate(EquipmentWorkItemFields.NextDueByDate, Nothing, True)) 'NextDueDate is not null

  filter.PredicateExpression.AddWithAnd(New FieldCompareValuePredicate(EquipmentWorkItemFields.NextDueByDate, Nothing, ComparisonOperator.LessEqual, EquipmentWorkItemFields.InActiveDate))

  Dim sorter As ISortExpression = New SortExpression()
  sorter.Add(New SortClause(EquipmentWorkItemFields.ActiveDate, Nothing, SortOperator.Ascending))

  FetchCollection(ewi, filter, pfp, sorter)
  Return ewi.ToList

I have two errors: 1. Unknown field RecurranceFields.NotifyDaysPrior. When I checked created SQL statement, fields only from EquipmentWorkItemEntity got selected. How can I include RecurranceFields.NotifyDaysPrior in Select list, so filter can go through?

  1. last filter breaks as well. I think it's because EquipmentWorkItemFields.InActiveDate is Nullable DateTime datatype. I get ": Cannot convert parameter value of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' to MySQL type 'MySqlType.DateTime'' Can I somehow put a condition: If Not InActiveDate Is Nothing, then apply this filter or there is another approach?

Thank you very much in advance, Galina.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Feb-2010 03:45:36   

Hi Galina,

gdolinskaya wrote:

  1. Unknown field RecurranceFields.NotifyDaysPrior. When I checked created SQL statement, fields only from EquipmentWorkItemEntity got selected. How can I include RecurranceFields.NotifyDaysPrior in Select list, so filter can go through?

You have to create a RelationCollection, add the involved relation (EquipmentworkItemEntity.Relations.RecurranceEntityVia...) and then pass such relationCollection to the Fetch routine. Please read Multi-entity filters for more info.

gdolinskaya wrote:

  1. last filter breaks as well. I think it's because EquipmentWorkItemFields.InActiveDate is Nullable DateTime datatype. I get ": Cannot convert parameter value of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' to MySQL type 'MySqlType.DateTime'' Can I somehow put a condition: If Not InActiveDate Is Nothing, then apply this filter or there is another approach?

It's not the field, is that you are using the wrong predicate class. You need to use a FieldCompareExpressionPredicate:

filter.PredicateExpression.Add(new FieldCompareExpressionPredicate(
    EquipmentWorkItemFields.NextDueByDate, ComparisonOperator.LessEqual,
    Nothing, EquipmentWorkItemFields.InActiveDate) );
David Elizondo | LLBLGen Support Team
Posts: 19
Joined: 11-Jan-2010
# Posted on: 11-Feb-2010 17:42:04   

Hi David,

It works. Thanks a lot for your help! You made my day simple_smile . Best, Galina.