MVC通用存储库通用dataColumn
我有一个通用存储库,用于处理常见的事情,例如 FetchAllData、GetbyID 等...无论如何,我想包含一个 Deactivate(T Entity)
方法,这样我就不会删除数据只需关闭它们的状态,这样用户就看不到数据,但我可以在需要时看到它。基本上,类似于:
public interface IGenericRepository<T> where T : class {
...somecode
}
public class GenericRepository<T> : IGenericRepository<T> where T : class {
public T GetbyID(int id) { ... }
public void Deactivate(T entity) {
entity.stat = 0; // I know that this stat is common in all tables. However,
// my problem is that I don't know how to make appear stat
// in IntelliSense.
}
}
我知道这是可以做到的,但我该怎么做?
I have a generic repository that I use for common things such as FetchAllData, GetbyID and so on... Anyway, I want to include a Deactivate(T Entity)
method so that instead of deleting data I will just turn their status off so the user will not see the data, but I can see it whenever I need. Basically, something similar to:
public interface IGenericRepository<T> where T : class {
...somecode
}
public class GenericRepository<T> : IGenericRepository<T> where T : class {
public T GetbyID(int id) { ... }
public void Deactivate(T entity) {
entity.stat = 0; // I know that this stat is common in all tables. However,
// my problem is that I don't know how to make appear stat
// in IntelliSense.
}
}
I know that this can be done, but I how do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
声明一个接口:
然后您的实体必须从 IDeactivatable 派生。
提示:您也可以添加泛型类型约束:
Declare a interface:
Then your entities must derive from IDeactivatable.
Tip: You can add a generic type constraint too: