Returning an entity by using a filter

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 17-Apr-2009 00:23:40   

Hi this may be a real easy question but i cant really think right now. I have a table called AcademicYear and it has a field called IsCurrent. Only one academic year can be current in collection.

I am trying to create an entity that returns the current academic year. (with filter IsCurrent = true) any ideas?

thanks -shane

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Apr-2009 04:07:04   

Hi shane,

As the field you want to filter is not a primary key, you cant fetch the entity directly but through a entitycollection. For exmample:

// the filter
PredicateExpression filter = new PredicateExpression(AcademicYearFields.IsCurrent = true);

// fetch
AcademicYearCollection toFindIn = new AcademicYearCollection();
toFindIn.GetMulti(filter);

// always will be only want current, so lets extract it
AcademicYearEntity theCurrentAY = toFindIn[0];
David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 17-Apr-2009 07:25:12   

hi thats how exactly i did it. i thought maybe there is some other easy way to it. i guess not thank you thou

-shane

daelmo wrote:

Hi shane,

As the field you want to filter is not a primary key, you cant fetch the entity directly but through a entitycollection. For exmample:

// the filter
PredicateExpression filter = new PredicateExpression(AcademicYearFields.IsCurrent = true);

// fetch
AcademicYearCollection toFindIn = new AcademicYearCollection();
toFindIn.GetMulti(filter);

// always will be only want current, so lets extract it
AcademicYearEntity theCurrentAY = toFindIn[0];