MVC通用存储库通用dataColumn

发布于 2024-11-25 00:44:06 字数 677 浏览 1 评论 0原文

我有一个通用存储库,用于处理常见的事情,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2024-12-02 00:44:07

声明一个接口:

public interface IDeactivatable {
    int stats { get; set; }
}

然后您的实体必须从 IDeactivatable 派生。

提示:您也可以添加泛型类型约束:

 [...] IGenericRepository<T> where T : class, IDeactivatable [...]

Declare a interface:

public interface IDeactivatable {
    int stats { get; set; }
}

Then your entities must derive from IDeactivatable.

Tip: You can add a generic type constraint too:

 [...] IGenericRepository<T> where T : class, IDeactivatable [...]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文