Print Page | Close Window

Generic Base Class for entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2284
Printed Date: 29-Jul-2026 at 7:10am


Topic: Generic Base Class for entities
Posted By: tersiusk
Subject: Generic Base Class for entities
Date Posted: 08-Nov-2010 at 7:20am
Hi

I have created a generic base class for my entities but I'm running into some issues with the serialization. I have defined the generic class as below. 
public abstract class EntityBase<T> : EntityBase
{      
}
I'm getting Error:
while getting known types for Type 'NetstarSecurity.DevForce.Model.EntityBase`1[T]'. The type must not be an open or partial generic class.
Now obviously my basetype is a open generic class...
I have tried adding the [KnownType(typeof(EntityBase<User>))] attribute but it still gives the same error. 

Please help. :)



Replies:
Posted By: smi-mark
Date Posted: 08-Nov-2010 at 8:26am
Why exactly do you need a Generic class?

When you have a base class EntityBase, User will inherit from EntityBase. You do not need to make it Generic


Posted By: tersiusk
Date Posted: 08-Nov-2010 at 8:48am
I want a generic class to do some type safe methods etc. For instance I want all my entities to have a GetAll method which need to return ObservableCollection<T>. 


Posted By: sbelini
Date Posted: 10-Nov-2010 at 4:23pm
Hi tersiusk,
 
Upon what operation are you getting the exception?
Are you using an injected base type? (you can do that in your model properties)
Can you upload a small sample (against northwindIB) reproducing the issue?
 


Posted By: tersiusk
Date Posted: 11-Nov-2010 at 12:58am
Hi sbelini

I'm getting the error on the SaveChanges()

Here is a sample solution.  uploads/988/DevforceTemplate.rar - uploads/988/DevforceTemplate.rar



Print Page | Close Window