Filtering

Posts   
 
    
Posts: 54
Joined: 22-Jun-2010
# Posted on: 06-Aug-2010 08:20:47   

Dear Support.

Am just trying understand how filtering works. I am trying to filter state and country by following method.

filterstate.Clear(); filterstate.Add(new FieldLikePredicate(StateFields.Description,null, "Bei%")); relationcountry.Relations.Add(CountryEntity.Relations.StateEntityUsingCountryId); filterstate.AddWithAnd(new FieldLikePredicate(StateFields.Description, null, "Chi%"));

       stateView.Filter = filterstate;

Problem : It returns zero records. But if I remove the line filterstate.AddWithAnd then it works fine. I dont understand what mistake I am doing here.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Aug-2010 08:57:54   

It must return Zero records.

There can be no row in the database which has the description field starts with "Bei" and at the same time it starts with "Chi". simple_smile

Posts: 54
Joined: 22-Jun-2010
# Posted on: 06-Aug-2010 09:43:20   

Walaa wrote:

It must return Zero records.

There can be no row in the database which has the description field starts with "Bei" and at the same time it starts with "Chi". simple_smile

Hi Walaa. You are the right man. DB has got matching records. But output it shows zero records.

My Complete code is reproduced below

******** Declarations****************

readonly DataAccessAdapter adapterstate = new DataAccessAdapter(); readonly EntityCollection<StateEntity> datasourcestate = new EntityCollection<StateEntity>(new StateEntityFactory()); readonly RelationPredicateBucket bucketcountry = new RelationPredicateBucket(); private readonly DataAccessAdapter adaptercountry = new DataAccessAdapter(); private readonly EntityCollection datasourcecountry = new EntityCollection(new CountryEntityFactory()); readonly IPrefetchPath2 prefetchPathstate = new PrefetchPath2((int)EntityType.StateEntity); IEntityView2 stateView; static readonly IPredicateExpression filterstate = new PredicateExpression(); private readonly RelationPredicateBucket relationcountry = new RelationPredicateBucket();

******** Declarations****************

******** Load Grid**************** prefetchPathstate.Add(StateEntity.PrefetchPathCountry); filterstate.Add(StateFields.Flag == StandardFlag.recordvalidflag); adapterstate.FetchEntityCollection(datasourcestate, null, prefetchPathstate); stateView = datasourcestate.DefaultView; stateView.Filter = filterstate; dgridstate.DataSource = stateView; ******** Load Grid****************

******** Filter****************

filterstate.Clear(); filterstate.Add(new FieldLikePredicate(StateFields.Description, null, "Bei%")); relationcountry.Relations.Add(CountryEntity.Relations.StateEntityUsingCountryId); filterstate.AddWithAnd(new FieldLikePredicate(CountryFields.Description, null, "Chi%"));

        stateView.Filter = filterstate;

******** Filter****************

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Aug-2010 10:39:04   

Please check the generated SQL and run it directly against the database to see what's happenening.

Refer to: Troubleshooting and Debugging

Posts: 54
Joined: 22-Jun-2010
# Posted on: 06-Aug-2010 11:25:31   

Walaa wrote:

Please check the generated SQL and run it directly against the database to see what's happenening.

Refer to: Troubleshooting and Debugging

Dubugger is not opening because something wrong in these two lines

relationcountry.Relations.Add(CountryEntity.Relations.StateEntityUsingCountryId);

       filterstate.AddWithAnd(new FieldLikePredicate(CountryFields.Description, null,
                                                "Chi%"));

CountryEntity.Relations.StateEntityUsingCountryId This is actually Int32

Error is Method not found: 'systems.string SD.LLBLGEN.PRO.ORMSupportsClasses.IPredicate.TOQueryText(Int32 By Ref)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Aug-2010 11:29:44   

Could you please post the stack trace.

(Edit) Also please try adding the relation the other way around:

relationcountry.Relations.Add(StateEntity.Relations.CountryEntity...);

(Edit) Oh you are filtering in-memory, you can use Linq2Objects or a DelegatePredicate.

similar thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14724

Posts: 54
Joined: 22-Jun-2010
# Posted on: 06-Aug-2010 11:58:18   

Walaa wrote:

Could you please post the stack trace.

(Edit) Also please try adding the relation the other way around:

relationcountry.Relations.Add(StateEntity.Relations.CountryEntity...);

(Edit) Oh you are filtering in-memory, you can use Linq2Objects or a DelegatePredicate.

similar thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14724

Solved. Just did as follows

filterstate.Clear(); filterstate.Add(new FieldLikePredicate(StateFields.Description, null, "Bei%")); filterstate.AddWithAnd(new EntityProperty("CountryName") % "Chi%"); stateView.Filter = filterstate;

But I hope am doing it the right way

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Aug-2010 02:43:41   

That's it wink

David Elizondo | LLBLGen Support Team