I want to create an interface for a generic DAO, and another for a generic entity, but I don't know how to get them to work (even compile >_<).
I have this for my entity:
Code:
public interface IDto<T>{
T Id { get; set; }
}
And I'm thinking of something like this for my DAO:
Code:
public interface IDtoDao<T> where T: IDto<U>{
T Create(T entity);
T Update(T entity);
T Retrieve(U id);
T Delete(T entity);
...
}
But it doesn't work because of the 'U' type :(
The idea is to get to something like this in the code:
Code:
// Here's where I specfy the type for the Id.
public class Item: IDto<Int32>{
Int32 Id {get; set; }
...
}
...
// I don't need to specify a type for the Id here, because I know Item inherits IDto<Int32>
public class ItemDao: IDtoDao<Item>{
...
public Item Retrieve(Int32 id) { ... }
...
}
Any ideas on how to write IDtoDao???? Thanks!