简体   繁体   English

MVVMLight,Silverlight,实体框架

[英]MVVMLight, Silverlight, Entity Framework

I have created我创造了

a) a basic application MVVMLight framework. a) 一个基本的应用程序 MVVMLight 框架。

b) another project in the same solution having an Entity Model (NorthwindModel.edmx). b) 同一解决方案中的另一个项目具有实体 Model (NorthwindModel.edmx)。

c) a WCF service to retrieve data through the entity model. c) 通过实体 model 检索数据的 WCF 服务。

Now I want to link a, b, and c together.现在我想将 a、b 和 c 链接在一起。 How do the project mentioned in a) above interact with the other two?上面a)中提到的项目如何与其他两个交互? How can I display/bind the data using the edmx in the View of the MVVM?如何在 MVVM 的视图中使用 edmx 显示/绑定数据? Do I have to write code in the ViewModel class/classes to achieve this?我是否必须在 ViewModel 类/类中编写代码才能实现这一点?

I browsed through many websites, checked many questions here on SO, but none seems to throw any light for me in this regard.我浏览了很多网站,在这里检查了很多关于 SO 的问题,但在这方面似乎没有一个对我有任何启发。 The examples that I saw involved a lot of coding in the ViewModel class.我看到的示例涉及 ViewModel class 中的大量编码。 If that's the only way to go about it, then why do people say MVVM with Silverlight requires very little coding?如果这是 go 关于它的唯一方法,那么为什么人们说带有 Silverlight 的 MVVM 需要很少的编码?

You can use WCF RIA Services to bridge the gap between ASP.NET and Silverlight.您可以使用 WCF RIA 服务来弥补 ASP.NET 和 Silverlight 之间的差距。

Get Started - WCF RIA Services开始使用 - WCF RIA 服务

You will need to create a Silverlight library project, add entity files as link to the project.您需要创建一个 Silverlight 库项目,将实体文件添加为项目的链接。 This will enable you to use the Entities in your Silverlight application.这将使您能够在 Silverlight 应用程序中使用实体。

how to add files as link 如何将文件添加为链接

Actually you need a Web project where you host your webservices, then you need your business logic layer and data access layer where you retrieve data, then you need the entities and a silverlight entities project.实际上,您需要一个 Web 项目来托管 Web 服务,然后您需要业务逻辑层和数据访问层来检索数据,然后您需要实体和 silverlight 实体项目。 After this you create your Silverlight project and add web service reference to it and thats it, now you are ready to use MVVM.在此之后,您创建 Silverlight 项目并添加 web 服务引用,就是这样,现在您可以使用 MVVM。

I think you could use this to refer how to build a solution with multiple projects and also have entity framework with WCF RIA services.我认为您可以使用来参考如何构建具有多个项目的解决方案,并且还具有带有 WCF RIA 服务的实体框架。

To ensure you project is running MVVM light you could use Nuget to inject the necessary files into your client project.为了确保您的项目正在运行 MVVM light,您可以使用 Nuget 将必要的文件注入您的客户端项目。 Information on this is available here相关信息可在此处获得

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM