FieldLikePredicate error

Posts   
 
    
uhib
User
Posts: 3
Joined: 12-Sep-2007
# Posted on: 12-Sep-2007 20:34:23   

I'm using C#.NET 2.0. LLBLGen info is shown below:

/////////////////////////////////////////////////////////////// // This is generated code. ////////////////////////////////////////////////////////////// // Code is generated using LLBLGen Pro version: 2.0.0.0 // Code is generated on: Tuesday, August 07, 2007 5:14:28 PM // Code is generated using templates: SD.TemplateBindings.SqlServerSpecific.NET20 // Templates vendor: Solutions Design. // Templates version: //////////////////////////////////////////////////////////////

I want to add filter with wildcard and I referenced http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8248

My source code is shown below:

EntityCollection<AccrualMasterTEntity> accrualMasterEntity = new EntityCollection<AccrualMasterTEntity>(); IPredicateExpression selectFilter = new PredicateExpression(); selectFilter.Add(AccrualMasterTFields.Conum == 2);

IExpression leftOperand = new Expression(AccrualMasterTFields.EmpStatus); EntityField2 ContentsField = AccrualMasterTFields.EmpStatus.SetExpression(leftOperand); string rightOperand = "F%";

    selectFilter.AddWithAnd(new FieldLikePredicate(ContentsField, rightOperand));

Code doesn't build. Error occurs at the place of FieldLikePredicate:

Argument '1': cannot convert from 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'

I tried to change 'EntityField2 ContentsField = ..." into "EntityField ContentsField = ...", then error occurs at AccrualMasterTFields.EmpStatus, with the same error message.

Why this happen and how to solve?

Thanks a million!!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Sep-2007 05:21:04   
David Elizondo | LLBLGen Support Team
uhib
User
Posts: 3
Joined: 12-Sep-2007
# Posted on: 13-Sep-2007 17:09:20   

Thanks daelmo. But the issue still exists.

I referenced your recommanded post and changed my code as below:

EntityCollection<AccrualMasterTEntity> accrualMasterEntity = new EntityCollection<AccrualMasterTEntity>(); IPredicateExpression selectFilter = new PredicateExpression(); selectFilter.Add(AccrualMasterTFields.Conum == 2);

** IEntityField empStatusField = AccrualMasterTFields.EmpStatus.SetExpression(new Expression(AccrualMasterTFields.EmpStatus));** FieldLikePredicate likePredicate = new FieldLikePredicate(empStatusField, "F%"); selectFilter.AddWithAnd(likePredicate);

    using (DataAccessAdapter adpTest = new DataAccessAdapter())
    {
        adpTest.FetchEntityCollection(accrualMasterEntity, new RelationPredicateBucket(selectFilter));
    }

The code doesn't build (as shown in bold). Error message is: Cannot implicitly convert type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'. An explicit conversion exists (are you missing a cast?)

Then I changed bold code to: IEntityField empStatusField **=(IEntityField) **AccrualMasterTFields.EmpStatus.SetExpression(new Expression(AccrualMasterTFields.EmpStatus));

The code can build but when running, still got error on the above place: Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'.

Anyone can help???

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Sep-2007 17:16:10   

IEntityField is used with SelfServicing, you are using the Adapter, then you should be using IEntityField2 instead. (or EntityField2 )

EntityField2 empStatusField = AccrualMasterTFields.EmpStatus.SetExpression(new Expression(AccrualMasterTFields.EmpStatus));

Hint: Anyway I don't understand what does that expression do. Why don't you just use:

FieldLikePredicate likePredicate = new FieldLikePredicate(AccrualMasterTFields.EmpStatus, "F%");

OR

selectFilter.AddWithAnd(AccrualMasterTFields.EmpStatus % "F%");
uhib
User
Posts: 3
Joined: 12-Sep-2007
# Posted on: 13-Sep-2007 18:57:13   

This code works!!!!

selectFilter.AddWithAnd(AccrualMasterTFields.EmpStatus % "F%");

Thank you so much Walaa!