如何在EF4和Silverlight中封装Self-tracking POCO?

发布于 2024-10-10 18:27:03 字数 1016 浏览 1 评论 0原文

我希望在名为 ModelLibrary 的类库中拥有 EntityFramework4 模型(.edmx 和 .context.tt)以及代码生成的实体,包括。名为 EntitiesLibrary 的单独 Silverlight 类库内的部分类 (.tt)。

通过这种方式,我希望与我的 silverlight 应用程序共享 EntitiesLibrary 以进行自我跟踪。为了在 silverlight 应用程序中使用这个项目,类库必须是 Silverlight 类库,我认为这就是问题开始的地方。

在下一步中,我添加了一个 Siverlight 应用程序项目,并将其托管在一个新的 ASP Web 项目中。在 ASP Web 项目中,我添加了一个 WCF 服务以及对 ModelLibrary 和 EntitiesLibrary 的引用,并在其中创建了一些 CRUD 操作。

现在,在 Silverlight 应用程序中,我向 Wcf 服务添加了一个服务引用,当单击“确定”时,它可以发现该服务;我收到一条错误消息:

无法加载文件或程序集“System.Runtime.Serialization,Version=2.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e”或其依赖项之一。系统找不到指定的文件。

在 Service.svc.cs 上 - 虽然没有编译问题 - Resharper 向我显示了操作中使用的实体的一些错误:

Module 'System, Version=2.0 .5.0,文化......'应该被引用。

???现在我完全陷入困境了。同样不寻常的是,在 ModelLibrary 的引用下和指向 EntitiesLibrary 的 ASP Web 主机下,我看到一个黄色标记。发生这种情况只是因为后者是 Silverlight 类库类型。如果我有一个普通的类库,就不会发生这种情况。

如果有人能给我建议那就太好了 非常感谢 卡韦

I would like to have the EntityFramework4 model (.edmx and .context.tt) in a Class Library called ModelLibrary and the code generated entities incl. the partial classes (.tt) inside a separate Silverlight Class Library called EntitiesLibrary.

This way I was hoping to share the EntitiesLibrary with my silverlight application for self-tracking. In order to consume this project within the silverlight application the class library has to be a Silverlight class library and I think this is where the problem starts.

In the next step I have added a Siverlight Application project and let it to be hosted in a new ASP Web project. In the ASP Web Project I have added a WCF Service and a reference to both ModelLibrary and EntitiesLibrary and created some CRUD operations in there.

Now within the Silverlight Application I add a Service Reference to the Wcf Service, while it can discover the service, when clicking ok; I get an error message:

Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

On the Service.svc.cs - while having no compiling issues - Resharper is showing me some errors on the entities used in the operations:

Module 'System, Version=2.0.5.0, Culture....' should be referenced.

??? Now I am completely stuck. Also unusual is that under references of ModelLibrary and under ASP Web host pointing to EntitiesLibrary I see a yellow marking. This happens only because the latter is of type Silverlight Class library. It doesn't happen if I had a normal class library.

Would be great if somebody had an advice for me,
Many Thanks
Kave

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

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

发布评论

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

评论(1

浪推晚风 2024-10-17 18:27:03

我遵循了 Jenny Lerman 的“实体框架”一书,她在其中创建了一个指向单独的类库中自动生成的实体的链接。

正如我所怀疑的那样,如果我使用控制台应用程序而不是 Silverlight,并且为我的实体提供一个普通的类库,那么它会工作得很好。添加的 Webservice 参考可以与实体一起创建代理。就像书上一样。

但是,如果类库属于 Silverlight 类库类型(由于 Silverlight 程序集的限制),则由于库不匹配,无法以某种方式创建指向 CLR 4.0 Web 服务的 WCF 服务引用。

我不再深入研究这个问题,从那以后我一直在尝试让 RIA 服务发挥作用,这似乎比自我跟踪 POCO 更有前景。

然而,适当的 n 层基础设施的问题仍有待发现。

I have followed the Jenny Lerman's "Entity Framework" book, where she creates a link to the auto generated entities within a seperate Class Library.

As I had suspected it, if I would use a Console Application instead of Silverlight and have a plain Class Library for my Entities, it would work just fine. The Added Webservice reference can work with the Entities to create a proxy. Just like in the book.

However if the class library is of type Silverlight Class library - due restriction in Silverlight assemblies - the WCF service reference pointing to a CLR 4.0 webservice can't be somehow created due mismatching libraries.

I stopped digging further into this matter and have been since trying to get RIA Services working, which seems far more promosing than Self Tracking POCOs.

Yet the problems with a proper n-Tier infrastructure still remains to be discovered.

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