can I do fetch a collection in a single statement.

Posts   
 
    
vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 14-Mar-2008 07:25:00   

class Appentity{entityid <pk>, entitygroupid <pk>, entitydesc}

where PHClientId is a another column that is not unique or foreign key

_adapter.FetchEntityCollection( collection, AppentityFields.entitygroupid == entitygroupid);

can I do fetch a collection in a single statement without using bucket, seems like a long tedious process to do that. thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Mar-2008 08:29:38   

If you want it in one line, the following code is sufficient.

_adapter.FetchEntityCollection( collection, new RelationPredicateBucket(AppentityFields.entitygroupid == entitygroupid));
vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 17-Mar-2008 04:33:32   

thinking about it, it makes sense when the fetchentitycollection method is performing in a most generic way. thanks

vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 17-Mar-2008 04:54:03   

is it possible to build the criteria dynamically such that the criteria is in a text form & that can be casted to corresponding like this "entity.entitygroupid == value" will cast into a predicate bucket? thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Mar-2008 06:02:13   

In that case you should cast by yourself: entity.entitygroupid == ((xxxx) value);

David Elizondo | LLBLGen Support Team
vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 17-Mar-2008 19:21:23   

thanks for your respons.

Is it possible to customize the code generator to use like the same way as unique key, primary key fetches to include indexed fields (either foreign key or non-foreign key, old legacy table designs where there are no physical foreign keys or that are not normalized) fetches instead of using predicates?

{ -primary key fetch public AppEntity(int entityid, entitygroupid) () public AppEntity(int entitygroupid) {}

entity = new Appentity(3); What should I do in the generated code? The table has a composite primary key & entitygroupid is a part of it. If I go and create a code to do that manually it doesn't work, may be I am trying doing something incomplete or wrong or something that is not possible.

thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 17-Mar-2008 20:55:56   

If something doesn't work: post the error and the code you tried. Also if an exception occurs, post a stacktrace.

Frans Bouma | Lead developer LLBLGen Pro
vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 18-Mar-2008 21:56:19   

'entity.entitygroupid' threw an exception of type 'SD.LLBLGen.Pro.ORMSupportClasses.ORMEntityOutOfSyncException' is the error I get. Infact I get that error for all columns in that entity.

        AppEntity entity = new AppEntity(38, true);

        using (DataAccessAdapter adapter = new DataAccessAdapter("UserID=dba;Password=****;DatabaseName=mydbnm;ServerName=mydbnm; AutoStop=No;CommLinks=TCPIP();Persist Security Info=True"))
        {
            adapter.FetchEntity(entity);
        }

I added the following code in the user code region

    //since AppID is already decimal lets polymorph using the boolean variable
    public AppEntity(System.Decimal valueID, Boolean isentitygroup)
        : base("AppEntity")
    {
        InitClassEmpty(null, CreateFields());
        if (startMonth)
        {
            this.EntityGroupID= valueID;
        }
        else
        {
            this.EntityPanelID= valueID;
        }

    }

The database schema is App{appID, appCode, appDesc, entitygroupid, entityPanelID} where all are decimal columns except appDesc is varchar(255)

PS: there is ONLY one record with that value 38 that I am passing

vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 18-Mar-2008 22:18:07   

there is ONLY one record with that value 38 that I am passing

Right after sending that message I was trying to retrieve using the primary key & realized that it was suppose to be 36.

And there was no record with that value 38.

So, the gen pro is throwing an incorrect message. when there is no record with that argument value in that database.

However, if I do the same with the primary key column it returns false & no error.

Seems like a bug to me now.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 19-Mar-2008 09:46:34   

What exactly is a bug? You created a new ctor, and added code which might not run properly. If you want to add additional code during the init phase, you should override OnInitializing in a partial class. The new CTor should simply refer to ': this(pk fields... )'

And WHEN and WHERE do you get the outofsync error message?

Frans Bouma | Lead developer LLBLGen Pro
vairam2008
User
Posts: 86
Joined: 11-Mar-2008
# Posted on: 19-Mar-2008 18:36:10   

Based on your explanation, it seems like I cannot use the constructor method to retrieve an entity using a non primary key, non-unique indexed key if I know that it is going to retrieve only one row on certain scenarios? In such cases I don't have to construct a collection. I just need an entity.

In my example, the table defintion is App{appID decimal <pk>, appCode varchar(5) <unique key>, appDesc varchar(255), entityGroupID decimal, entityPanelID decimal } entityGroupID is non-unique index, entityPanelID is non-unique index.

I get the error message when I call adapter.FetchEntity(entity) in my script i posted in the earlier post.

thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 19-Mar-2008 18:46:33   

You can, use adapter.FetchNewEntity<T>(filter). That method returns the entity matching the filter.

Frans Bouma | Lead developer LLBLGen Pro