Upgrade-Problems

Posts   
 
    
RolandE
User
Posts: 7
Joined: 06-Nov-2007
# Posted on: 06-Nov-2007 12:13:39   

Due to upgrading an older project to .NET 3.0 we decided to try to switch to a newer version of LLBLGEN too.

One of the major problems we are now facing is, that a part of the code is not working anymore.

Current code:

<--- Code Snippet --->

public void Delete(int ID) { EntityCollectionBase Coll;

Coll = (EntityCollectionBase) Assembly.GetAssembly(typeof (TypeDefaultValue)).CreateInstance("Namespace.CollectionClasses." + m_TableName + "Collection", true);

..... }

<--- End --->

Can somebody please tell, how we can transfer this piece of code to the current Version of LLBLGEN?

Best regards and many thanks in advance

Roland Ebner

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 06-Nov-2007 12:55:33   

What does 'doesn't work mean: doesn't compile, you get an exception, no results or other?

from which version did you migrate, have you followed the 'migrating your code' section in the manual?

Frans Bouma | Lead developer LLBLGen Pro
RolandE
User
Posts: 7
Joined: 06-Nov-2007
# Posted on: 06-Nov-2007 13:53:42   

Doesn't compile.

It tells me to use

EntityCollectionBase<TEntity> Coll;

instead of

EntityCollectionBase Coll;

But I don't know how to get the Assembly of the used Entity.

I am upgrading from version 1.0.2004

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 06-Nov-2007 19:59:12   

try using IEntityCollection instead.

RolandE
User
Posts: 7
Joined: 06-Nov-2007
# Posted on: 07-Nov-2007 07:25:47   

The problem now is, that IEntityCollection doesn't support .Transaction and .AddNew.

Is there any other option to change the current code?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Nov-2007 10:50:05   

May I ask, why are you instantiating collections in this way? There might be an easier way.

My 2 cents: CollectionClasses inherit from EntityCollectionBase<TEntity> eg: CustomerCollection : EntityCollectionBase<CustomerEntity>

And EntityCollectionBase<TEntity> implements IEntityCollection out of many interfaces it implements.

So I guess if you use IEnitityCollection to instantiate an EntityCollection you may later cast it back to that EntityCollection or to EntityCollectionBase<TEntity>.

RolandE
User
Posts: 7
Joined: 06-Nov-2007
# Posted on: 07-Nov-2007 11:07:14   

I have a base class (called SimpleManager) which does all the "easy" things for me.

Here a quick overview of some functions: void Save(DataSet) DataRow GetByID(int ID) void Delete(int ID)

All i have to do now is to create a new instance of SimpleManager, set his TableName property to the name of the table I want to query and call GetByID to get a single row.

Because all of our PrimaryKeys are in the format "ID_"+tablename, it is very easy to search for a PK.

So in this situation all I know about the collection (also entity, view, a.s.o.) is its name (Tablename + "Collection").

I don't see a way to cast the collection to that specific type because I only know it's name.

This code did work now for over 2 years. So it's not the question why we do this. It's more the question "How can we do this with the new Version?"

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Nov-2007 12:18:33   

Well you can do the same thing using a string for the factoryType as follows:

IEntityFactory factory = (IEntityFactory)Activator.CreateInstance(factoryType);
IEntityCollection coll = factory.CreateEntityCollection();
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 07-Nov-2007 13:04:51   

Additionally: AddNew has been removed as it's part of IBindingList, which is now part of the entity view. If you want to add a new entity, grab the factory like this: IEntity newEntity = col.EntityFactoryToUse.Create();

You don't normally need to access the .Transaction property. If you want to: ((ITransactionalElement)col).Transaction

Frans Bouma | Lead developer LLBLGen Pro