CommonLibrary.NET 存储库和 EF 4 一起工作吗?

发布于 2024-11-25 12:38:56 字数 551 浏览 2 评论 0原文

我想在我的项目中使用 CommonLibrary.NET,但我有遗留代码,无法进行 Code First 建模,我使用 VS2010 工具从数据库生成我的模型。

但设计工具生成的开箱即用实体似乎无法与 CommonLibrary 中的存储库一起使用,它给出了错误:

错误 1 ​​类型“RepositoryTest.UserInfo”不能用作类型 泛型类型或方法中的参数“T” 'ComLib.Entities.RepositorySql'。没有隐式引用 从“RepositoryTest.UserInfo”转换为 'ComLib.Entities.IEntity'。

有人也遇到过这个问题吗,如果有的话也许有一个简单的解决方案?

我还想知道是否有人有一个好的替代框架或项目来实现支持 EF 实体的存储库。 我是 TDDing,所以我想在同一个框架中实现内存中的存储库,这就是我首先选择这个框架的原因。

I would like to use CommonLibrary.NET in my project but I have legacy code and can't do Code First modeling, I use the VS2010 tool to generate my model from the DB.

But it seems that the out of the box entities that the design tool generated can't be used with the repositories in the CommonLibrary, It gives the error:

Error 1 The type 'RepositoryTest.UserInfo' cannot be used as type
parameter 'T' in the generic type or method
'ComLib.Entities.RepositorySql<T>'. There is no implicit reference
conversion from 'RepositoryTest.UserInfo' to
'ComLib.Entities.IEntity'.

Did anyone had this problem also, if so maybe there is a simple solution?

I would like also to know if anyone have a good alternative framework or project that implements repositories that support EF entities.
I am TDDing so I would like to have an implementation of a repository in memory in the same framework, This was the reason I choose this framework in the first place.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

独留℉清风醉 2024-12-02 12:38:56

看起来 ComLib.Entities.RepositorySql 有一个通用约束,类似于

public class RepositorySql<T> where T : IEntity
{
    // ...
}

这意味着您的实体类必须按顺序实现此接口 ComLib.Entities.IEntity用作存储库的通用类型参数。所以你的类必须如下所示:

public class UserInfo : IEntity
{
    // implementation of IEntity
    // look in documentation what you have to implement
    // or hit ctrl-period in Visual Studio on IEntity
    // to get a default implementation

    // your custom code
}

It looks that ComLib.Entities.RepositorySql<T> has a generic constraint, something like

public class RepositorySql<T> where T : IEntity
{
    // ...
}

This means that your Entity classes have to implement this interface ComLib.Entities.IEntity in order to be used as the generic type parameter of the repository. So your class must look like:

public class UserInfo : IEntity
{
    // implementation of IEntity
    // look in documentation what you have to implement
    // or hit ctrl-period in Visual Studio on IEntity
    // to get a default implementation

    // your custom code
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文