在 WPF、Silverlight 和 ASP.NET 之间共享公共 DAL

发布于 2024-09-26 14:01:59 字数 173 浏览 2 评论 0原文

在 WPF、Silverlight 和 ASP.NET 之间共享相同数据访问层的最佳方法/技术是什么?

我正在使用 ADO.NET 实体框架,并且正在考虑使用存储库模式创建 DAL。然后使用 RIA 服务作为虚拟中间人来连接 Silverlight 和 ASP.NET。这是一个可靠的计划还是还有其他更好的解决方案?

What is the best method/technology to sharing the same data access layer between WPF, Silverlight, and ASP.NET?

I am using ADO.NET Entity framework, and was thinking of a creating a DAL using the Repository pattern.Then using the RIA Services as a dummy middle man to connect Silverlight and ASP.NET. Is this a solid plan or are there other better solutions out there?

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

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

发布评论

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

评论(2

流心雨 2024-10-03 14:01:59

我喜欢使用的解决方案之一如下:
- 有一个仅存储实体(例如:玩家、游戏、实体)的项目,根本不引用数据库。
- 有一个实现存储库模式的项目(存储库,存储库等......)
- 使用 ADO.NET 实体框架代码优先方法来映射数据库(它创建项目中包含的实体的动态子对象,请参阅 ScottGu 的博客以获取有关如何使用它的说明)

可以将 Silverlight 连接到您的模式使用 Ria 服务或经典 WCF 服务。通常我会尽可能尝试使用 WCF,因为 Ria Services 并不真正符合 MVVM 开发。

如果您想要使用 WCF 并与 Silverlight 共享您的 DAL 实体,您可以创建一个 MyDal.Silverlight Silverlight 类库项目,并添加符号链接而不是您想要与 Silverlight 共享的每个实体的副本。然后,当您使用 Visual Studio 添加服务引用时,它会足够智能,不会为您的 Silverlight 项目创建玩家、游戏和用户的副本。

如果您想使用 Ria 服务,它无论如何都会创建您实体的副本。

希望对

约翰有帮助

One of the solutions I like to use is the following :
- Have a project storing only the entities (for example : Player, Game, Entity) with no reference to the database at all.
- Have a project implementing the repository pattern (Repository, Repository etc...)
- Use ADO.NET Entity Framework code first approach to map with the database (it creates a dynamic child object of your entities contain in your project, see ScottGu's blog for an explanation on how to use it)

Connecting Silverlight to your pattern can be done with Ria Services or classic WCF services. Usually I try to use WCF whenever possible as Ria Services is not really compliant with an MVVM development.

If you want to use WCF and share your DAL entities with Silverlight you can create a MyDal.Silverlight Silverlight class library project and add symbolic link instead of copies of every entities you will want to share with Silverlight. Then when you'll add a service reference with visual studio it will be smart enough to not create copies off Player, Game and User to you Silverlight project.

If you want to use Ria Services it will create copies of you entities anyway.

Hope that helps

John

拥抱影子 2024-10-03 14:01:59

RIA 服务

RIA 服务肯定会减轻您所有 WCF 管道的负担。它有一些小缺陷(缺少某些数据类型),但大多数问题都有解决方法。

验证模型(使用属性装饰和自定义验证器)非常强大,是悬挂业务规则的好地方。

RIA 可以与 ASP.Net 愉快地共存,因此这是另一个优点。在幕后它只是另一个 WCF 服务。我们很高兴将 RIA 服务与 MVVM Prism 一起使用。

ADO.Net EF 模型

这是一个久经考验的功能丰富模型。我发现的唯一问题与多对多关系有关。再次有解决方法。

DAL

由于 RIA 变更集是为您管理任何内容的,包括 POCO,因此这是一个区域最需要关注。将 EF 模型直接暴露给 RIA 被认为是“不好的”,并且这肯定不会使您免受数据更改的影响。

我还不能具体推荐任何一种模式(仍在试验中),但请确保您的选择与 IQueryable 兼容。分页功能和附加到服务器端执行的 Linq 查询是您不想失去的功能!

RIA Services

RIA services will certainly take the burden off you for all the WCF plumbing. It has a few minor flaws (lack of certain data types), but there are workarounds for most problems.

The validation model (using attribute decoration and custom validators) is very strong and a great place to hang business rules.

RIA coexists happily with ASP.Net, so that is another plus. Behind the scenes it is just another WCF service. We are happily using RIA services with MVVM and Prism.

ADO.Net EF model

This is a tried and tested feature rich model. The only problems I have found related to many-to-many relationships. Again there are workarounds.

DAL

As RIA change sets are managed for you on anything, including POCO, this is the area that will need the most attention. It is considered "bad" to expose your EF model directly to RIA and that will certainly not insulate you from data changes.

I can't specifically recommend any one pattern yet (still experimenting), but make sure your choice is compatible with IQueryable. The paging feature and appending to Linq queries for server-side execution are features you do not want to lose!

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