binding to datasource EntityCollection

Posts   
 
    
Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 29-Nov-2007 03:57:39   

_customers is a datasource(EntityCollection) created by llblgen code set to TblCustomersEntityfactory

_customers=CustomersCollection

Value of type 'Shop.HelperClasses.EntityCollection(Of Shop.EntityClasses.TblCustomersEntity)'

cannot be converted to 'Shop.HelperClasses.EntityCollection'.

why am i getting an error?

I retrieve the collection from the database..convert to xml....pass to winform from webservice..then try to assign to _customers but get the above error.

Hope this makes sense?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Nov-2007 04:40:22   

Hi Anthony,

Please post the relevant code snippet where you create the collection and where you get the error. Also please post the exception stacktrace and the LLBLGen version and Runtime libraries version you are using, so we can help you in a better manner.

David Elizondo | LLBLGen Support Team
Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 29-Nov-2007 04:53:19   

Private _tblCustomersEntityCollection As New EntityCollection(Of TblCustomersEntity)

'using webserive to get collection by using writexml otblCustomersBytes = wsthisSolution.GettblCustomersEntityCollectionString(False)

'populate variable _tblCustomersEntityCollection.ReadXml(tblCustomersXML)

does this help?this occurs at designtime not runtime. Using v2.5

Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 29-Nov-2007 04:54:28   

then i try to assign it to

_customers=tblCustomersEntityCollection

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Nov-2007 08:46:22   

_customers=tblCustomersEntityCollection

And customers definition code is?

David wrote:

Also please post the exception stacktrace and the LLBLGen version and Runtime libraries version you are using, so we can help you in a better manner.

check the following link to know how to get the LLBLGen Pro runtime library version: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7720

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 29-Nov-2007 11:50:58   

You can't send generics over a webservice as webservices don't support generic types. So you can't use a webmethod: public EntityCollection<T> GetEntities<T>() {} or something like that, you have to return a non-generic type.

As EntityCollection() is a non-generic type, under the hood it is: (EntityCollection<EntityBase2>. ) THis will cause co-variance problems: List<string> isn't a subtype of List<object>

So in your webmethod: fill an EntityCollection instance, not an EntityCollection<T> instance.

Frans Bouma | Lead developer LLBLGen Pro
Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 29-Nov-2007 14:30:45   

Any advantages/disadvantages doing your suggestion?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Nov-2007 15:14:25   

Advantages: now you can pass the collection through the webService. Disadvantages: I can't think of any.

Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 30-Nov-2007 11:00:34   

Is it possible to convert from EntityCollection(Of tblUsers) to EntityCollection?

Me._memberusers = tblUsersEntity

where

_memberusers.EntityFactoryToUse = New Global.SB.SBH.Dal.Adapter.llblgen.FactoryClasses.TblUsersEntityFactory

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Nov-2007 12:22:24   

You could access everything in the collection via IEntityCollection, which is the non-generic interface to the generic collection.

myNonGenericCollection = (IEntityCollection)myGenericCollection;

Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 30-Nov-2007 23:59:44   

Me._memberusers = CType(CType(UltraGridMembers.Selected.Rows(0).ListObject, TblCustomersCollection), IEntityCollection)

where _memberusers is entitycollection

does not work as you mentioned.

Posts: 254
Joined: 16-Nov-2006
# Posted on: 01-Dec-2007 23:28:08   

1) What's the exact type of _memberusers as this should be IEntityCollection 2) What compilation error are you getting? Presumably there is one wheny you say this does not work.

Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 02-Dec-2007 13:51:29   

Unable to cast object of type

'SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection`1[SmallBiz.SBH.Dal.Adapter.llblgen.EntityClasses.TblUsersEntity]' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection'.

where _memberusers As Global.SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Dec-2007 03:51:07   

Hi Anthony,

I think we are walking in circles here disappointed . Please provide as much information as you can (http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7720).

Would be helpful if you attach your relevant project files.

David Elizondo | LLBLGen Support Team
Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 03-Dec-2007 04:15:41   

STARTING FROM THE BEGINNING.....

Basically trying to cast to EntityCollection from a generic type

Dim _EntityCollection As New EntityCollection(Of TblCustomersEntity) Dim oCustomers as EntityCollection

oCustomers =ctype(_EntityCollection,EntityCollection) ***give error

***Error Value of type 'SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection(Of SmallBiz.SBH.Dal.Adapter.llblgen.EntityClasses.TblCustomersEntity)' cannot be converted to 'SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection'.

Using adapter mode Build 2.5 28August 2007

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Dec-2007 08:20:50   

Please try the following:

oCustomers =ctype(_EntityCollection, IEntityCollection2)

I know you have tried casting to the IEntityCollection before but the error you have provided was strange

Unable to cast object of type 'SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection`1[SmallBiz.SBH.Dal.Adapter.llblgen.EntityClasses.TblUsersEntity]' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection'.

As if you were trying to cast an EntityCollection to an Entity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 03-Dec-2007 12:00:43   

Anthony wrote:

STARTING FROM THE BEGINNING.....

Basically trying to cast to EntityCollection from a generic type

Dim _EntityCollection As New EntityCollection(Of TblCustomersEntity) Dim oCustomers as EntityCollection

oCustomers =ctype(_EntityCollection,EntityCollection) ***give error

***Error Value of type 'SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection(Of SmallBiz.SBH.Dal.Adapter.llblgen.EntityClasses.TblCustomersEntity)' cannot be converted to 'SmallBiz.SBH.Dal.Adapter.llblgen.HelperClasses.EntityCollection'.

Using adapter mode Build 2.5 28August 2007

This error is caused because: EntityCollection(Of TblCustomersEntity) isn't a subtype of EntityCollection(Of EntityBase2), which is the base type of EntityCollection. This is the same as: List(Of String) isn't a subtype of List(Of Object), although String is a subtype of Object. This means that you can't cast a List(Of String) to a List(Of Object) type.

So you should do: Dim _EntityCollection As New EntityCollection()

or as Walaa said, cast to IEntityCollection2

You're using adapter, not selfservicing.

Frans Bouma | Lead developer LLBLGen Pro