是否可以为使用实体框架的DAL设置接口库? [英] Is It Possible To Setup An Interface Library For A DAL Using Entity Framework?

查看:78
本文介绍了是否可以为使用实体框架的DAL设置接口库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型库(名称空间 Test.App.Model.EF )与实体框架实现。这有我想要使用的EF设计师提供的所有实体。在这个 Model.EF 实现中,我有几个存储库类。我想为这些类创建接口,并将它们放在一个独立的接口库( Test.App.Model.Interface )中。所以我这样做,显然实现库需要一个引用的接口。但是,我注意到接口需要知道EF设计器中的对象(因为我想重用它们)。我不能从界面库创建引用到ef实现,因为我将有一个循环引用。

I have a model library (namespace Test.App.Model.EF) with the Entity Framework implementation in it. This has all of the entities provided in the EF designer for me which I want to use. Within this Model.EF implementation, I have several repository classes. I want to create interfaces for these classes and place them in a seperate interface library (Test.App.Model.Interface). So I do so, obviously the implementation library needs a reference the interfaces. BUT, I notice that the interfaces need to know about the objects in the EF designer (since I want to reuse them). I can't create a reference from the interface library to the ef implementation because then I'll have a circular reference.

所以,当我写这个,我是得出结论,我可能需要一个具有实体框架创建实体的 Test.App.Entities.EF 。这样我的界面lib可以引用,而不需要知道 Model.EF

So, as I write this, I'm coming to the conclusion that I'll probably need a Test.App.Entities.EF that has the Entity Framework "created" entities. That way my interfaces lib could reference without having to know about the Model.EF.

这听起来像是要走的路吗?

Does that sound like the way to go?

推荐答案

好的,所以经过很多摔跤之后,我发现了描述情况的嗡嗡声。我在这里找的是持久性无知。这是什么会使我在线程中描述的事情发生。那么我们使用的实体框架(不是4.0)不支持这个(除非你像本来就这样完成 here )。

Ok, so after much wrestling with this, I found the buzz term that describes the situation. What I'm looking for here is called "Persistence Ignorance". This is what would make what I described in my thread happen. Well the Entity Framework that we use (not 4.0) does not support this yet (unless you go homegrown like done here).

有了这个说法, EF 4.0将具有这个功能,但从我的理解,它与.NET 4.0(为什么它被称为EF 4.0在第一位),这不会在我们的生产服务器上很快。由于我们已经决定使用这种技术,因此我们对接口的存储库抽象将被搁置,直到升级到4.0是一个可行的选择。

With having that said, EF 4.0 will have this feature but from what I understand, it's coupled with .NET 4.0 (why it's called EF 4.0 in the first place) and that's not going on our production servers anytime soon. Since we've decided to go with this technology, our repository abstraction to interfaces will be placed on hold until upgrading to 4.0 is a viable option.

让这是寻求相同信息的人的注意事项。还请让我知道,如果这听起来不正确(因为我会很乐意让这个事情发生得更早,但后来我不希望我的团队跳过篮球,后来的实施将纠正这个问题)。感谢所有!

Let this be a caveat for those seeking the same information. Please also let me know if this sounds incorrect (because I would love to make this happen sooner then later but I don't want my team jumping through hoops when a later implementation will remedy the issue). Thanks all!

这篇关于是否可以为使用实体框架的DAL设置接口库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆