searching an entity collection

Posts   
 
    
Bexm
User
Posts: 8
Joined: 23-May-2007
# Posted on: 23-May-2007 16:04:46   

Hello

I am trying to create a new entity collection by filtering an existing one, my pseudo code is here:

        EntityCollection newConfigs=new EntityCollection(new ConfigsEntityFactory());;

        foreach(ConfigsEntity entity in existingconfigs)
        {

            //IF entity.key is already in new configs THEN
            //  IF entity.portalID is not Null THEN
            //      update newconfigs.Value with entity.value,
            //  END
            //ELSE
            //  Add entity to newconfigs

        }

Is this possible? If so how? I have found a ".contains" on the entity collection but I can't work out how to use it or update the item its found..

Thanks

Bex

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 23-May-2007 16:45:27   

check out the help docs Generated code - Using the EntityView2 class, Adapter or Generated code - Using the EntityView2 class, Self Service.

you can create a PredicateExpression to filter the results into an EntityView. this view could either be bound to a data control, or converted to a new EntityCollection.

Not all predicates available on the server(db) is available on the client (code).

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-May-2007 16:51:06   

Are you using LLBLGen Pro 2.0? Or are using an older version? (Please specify)

If it's v.2.0, then it's a lot easier to use an EntityView to filter an EntityCollection. Otherwise if you are not filtering on the PK of the entity, then what you are doing is the right approach (check the pseudo code below).

            EntityCollection newColl = new EntityCollection(new ConfigsEntityFactory());;
            foreach(ConfigsEntity entity in existingconfigs)
            {

                IF entity.key is already in new configs THEN
                    IF entity.portalID is not Null THEN
                        newColl.Add(entity);
                    END
                ELSE        
            }
Bexm
User
Posts: 8
Joined: 23-May-2007
# Posted on: 23-May-2007 17:20:33   

Hi Walaa

Thanks for the information but I have worked out what SQL I would need to use to do this without trying to filter it in the code.

** WITH Config AS (

select [key],portalid,ROW_NUMBER() OVER

(PARTITION BY [key] ORDER BY [key],portalID desc) as 'number'

from configuration where (portalID='73DA12E8-0D79-42D6-8C19-B0AE0F0BC34A' or portalID is null)

) select * from config

where number =1 order by [key] **

Are you able to let me know how I would do this in llblgen? Please bear in mind that the "key" column is not the primary key of the table, it is just a normal column.

PortalID is something that would be passed in, depending on the page being displayed.

Thanks

Bex

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-May-2007 17:38:34   

I'd suggest putting it in a stored procedure and call it from LLBLGen Pro code.

Bexm
User
Posts: 8
Joined: 23-May-2007
# Posted on: 23-May-2007 17:45:24   

Walaa wrote:

I'd suggest putting it in a stored procedure and call it from LLBLGen Pro code.

Really??!! Isn't there a way of doing this or similar with LLBLGEN?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39914
Joined: 17-Aug-2003
# Posted on: 23-May-2007 21:13:43   

As Walaa said: if you're using v2.0: define a view with the filter, then create a new collection from the view (it's a method on the view) and you're done. In v1.0.2005.1, you have to traverse the collection manually. To find an entity in a collection in 1.0.2005.1, you use IndexOf(entity), and it will do a linear search of the entity using Equals(), which compares PK values.

WHich version of llblgen pro are you using?

Frans Bouma | Lead developer LLBLGen Pro