Accessing Collections

Posts   
 
    
can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 30-Sep-2005 15:46:53   

I am just starting with LLBLGen and am hoping that someone can help me with accessing collections.

I am using the extended adapter templates with the 2005 beta. As such, reading the documentation, it appears that collections are returned as type 'EntityCollection'.

My actual questions are in bold below to seperate them from the background information.

I am trying a simple selection of all records from a table, wrapped in a ObjectManager class with a method called GetAllContent():

public EntityCollection GetAllContent() {

        EntityCollection content = new EntityCollection(new MyContentEntityFactory());

        try
        {

            using( DataAccessAdapter odapt = new DataAccessAdapter())
            {

                IRelationPredicateBucket bucket = new RelationPredicateBucket();

                odapt.FetchEntityCollection(content,bucket);    

                return content;

            }
        }

Using VB.NET, to access the entity properties of a single member of the returned collection , I seem to have to explicity convert it to the entity type of the contained entity?

Dim cm As New Pavliks.TestProject.BusLogic.ContentManager Dim colContent As Pavliks.TestProject.HelperClasses.EntityCollection

colContent = cm.GetAllContent()

        MsgBox(CType(colContent.Item(1), Pavliks.TestProject.EntityClasses.MyContentEntity).ContentHtml)

Is this correct? Since there are no strongly typed collection objects of type MyContentEntity with the adapter template, must I always explicity convert it using CType?

With the new expression overloading syntax available in the C# generated code, I am pursuing C# now instead of VB.NET. I can't seem to get to the basic entity properties, 'ContentHtml' in this case, using C#.If the explicit conversion question above is the way I have to do it, what is the equivalent C# code to read a specific MyContentEntity instance in the collection class and access the ContentHtml property?

Pavliks.TestProject.HelperClasses.EntityCollection content; Pavliks.TestProject.BusLogic.ContentManager manager = new Pavliks.TestProject.BusLogic.ContentManager();

content = manager.GetAllContent();

messagebox.show((Pavliks.TestProject.EntityClasses.MyContentEntity)content.Items[1].ContentHTML)

Thanks for your time. I hope someone more experienced can help. LLBLGen and the whole O/R mapper way of doing things rocks! Can't wait to get over this initial learning curve and really use it's advantages.

Can1

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Sep-2005 17:04:16   

To get an item insde a collection, you should cast that item to its type.

So in VB.Net you suse CType for type casting, and in C# you use the following simple casting:

(Pavliks.TestProject.EntityClasses.MyContentEntity)colContent.Items[i];

can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 30-Sep-2005 17:45:48   

Thanks.