pilotboba wrote:
Otis wrote:
Ok, here's the problem:
public abstract class EntityBase2
{
public EntityBase2()
{
}
}
public class CustomerEntity : EntityBase2
{
private string _name;
public CustomerEntity()
{
_name = string.Empty;
}
}
public abstract class EntityCollectionBase2<T>
where T:EntityBase2, new()
{
public EntityCollectionBase2()
{
T t = new T();
}
}
public class EntityCollection : EntityCollectionBase2<EntityBase2>
^^^^^^^^^^^^^^^^^^^^^^^^^
{
public EntityCollection()
{
}
}
You get an error because EntityBase2 is an abstract class. In order to instantitate EntityCollectionBase2<EntityBase2>, EntityBase2 can't be abstract. I also don't think you would code this anyway... wouldn't you generate:
Public Class EntityCollection : EntityCollectionBase2<CustomerEntity>
???
The problem is that that EntityCollection can only contain CustomerEntity instances, and I need an entitycollection class which can contain any entity instance, as it is today.
You could have EntityBase2 impelement IEntityBase2, change the constraints on your generic to WHERE T : IEntityBase2. Of course you still have to use the type above when you subclass. Not sure that you need to introduce an empty interface.
I guess I am not sure what you are trying to do. Why can't the EntityCollection non-generic stay as is for backward compatiblity?
BOb
The EntityCollection class is only for backwards compatibility
. It's currently part of the ormsupportclasses but today I'll move it back to the generated code as it will otherwise break all those winforms which have an entitycollection on top of it.
In 1.0.2005.1, EntityCollection simply derives from EntityCollectionBase2 which derives from CollectionBase. In v2, I have a general collectioncore<T> class, which is the base for both EntityCollectionBase and EntityCollectionBase2. The generic EntityCollection<T> derives from EntityCollectionBase2<T>, however for backwards compatibility I need a non-generic collection class. Also for design time databinding I need a non-generic collection class, because design time databinding doesn't work with generics (in a way understandable, but still odd). And because it has to contain any entity, it can only be EntityCollection : EntityCollectionBase2<EntityBase2> or EntityCollection: EntityCollectionBase2<IEntity2>. The latter won't compile because the collection requires EntityBase2 internally, and the former will compile but then I can't create a new instance.
So the code you write today:
EntityCollection customers = new EntityCollection(new CustomerEntityFactory());
still works, though it's not a generic collection, so this won't compile:
CustomerEntity c = customers[0];
And because C# doesn't support covariance, this also won't compile:
EntityCollection customers = new EntityCollection<CustomerEntity>(new CustomerEntityFactory());
even though CustomerEntity implements EntityBase2.