我正在尝试为crud操作创建一个基类,但是无法弄清楚如何将这个部分连接起来或者是否可能。我正在使用EDMX生成dbcontexts和pocos,所以,理想情况下,我想创建一个基类,从中我可以派生出所有的crud方法。
接口:
public interface IGenericCrud<T> where T : class
{
void Add(T entity);
}
实现:
public abstract class MyImplementation : IGenericCrud<KnownModel>
{
protected myEntities context;
public MyImplementation()
{
context = new myEntities();
}
void Add(KnownModel entity)
{
// This doesn't work, but it's what I'd like to accomplish
// I'd like to know if this possible without using ObjectContexts
context.KnownModel(add entity);
}
}