MVVMLight, Silverlight, Entity Framework - silverlight

I have created
a) a basic application MVVMLight framework.
b) another project in the same solution having an Entity Model (NorthwindModel.edmx).
c) a WCF service to retrieve data through the entity model.
Now I want to link a, b, and c together. How do the project mentioned in a) above interact with the other two? How can I display/bind the data using the edmx in the View of the MVVM?
Do I have to write code in the ViewModel class/classes to achieve this?
I browsed through many websites, checked many questions here on SO, but none seems to throw any light for me in this regard. The examples that I saw involved a lot of coding in the ViewModel class. If that's the only way to go about it, then why do people say MVVM with Silverlight requires very little coding?

You can use WCF RIA Services to bridge the gap between ASP.NET and Silverlight.
Get Started - WCF RIA Services

You will need to create a Silverlight library project, add entity files as link to the project.
This will enable you to use the Entities in your Silverlight application.
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. After this you create your Silverlight project and add web service reference to it and thats it, now you are ready to use 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.
To ensure you project is running MVVM light you could use Nuget to inject the necessary files into your client project. Information on this is available here

Related

Silverlight / Prism / RIA : How to create the optimal infrastructure?

Since days I am reading and researching and still struggling how to create the perfect infrastructure. Since there are no Prism 4.0 templates as such, I came up with a strategy, but I need to be sure this is the right strategy and I would appreciate an advice from experienced PRISM/RIA developers.
I use PRISM 4.0, RIA Services 1.0 Sp1 Beta, Silverlight 4.0, Entity Framework 4.0
1) Client side
I created first a "Silverlight Business Application", which creates a Web.host and a Silverlight client application with implemented RIA authorization. The initially created Silverlight client application shall be used as the Shell project.
2) Infrastructure project (Common)
This project would contain some common Prism MEF attributes and perhaps the entity models that are auto generated by RIA as well as the Service Interface. The idea is to create a simple Silverlight Class Library, and under Properties of the project, I would select for the dropdown ‘WCF Ria Services Link ’ to point to the host.Web project that contains the Ria Services. Then after the rebuilding, I am able to see the entity models within the Class Library and these could then be shared between the prism modules to feed their ViewModels etc.
3) Service layer
Should I create the EF4 Model on the Web.host project and add the Domain Service in there? Then I would extract an interface from the Domain Service and put the interface into the Infrastructure (Common) project. The Web.Host therefore needs to reference the Infrastructure (common) project to get access to the interface. On the client side the interface may be used by MEF to retrieve or mock the service . However I am concerned about the service referencing a common project that contains also the client-side generated entities.
4) Authorization
Also a bit concerned about the authorization, shall I leave everything on the Shell project? Or do I have to move anything to the Infrastructure (common) project to share it?
Since this is my first time designing with PRISM, I might have misunderstood or forgotten some aspects. Please feel free to improve my suggestions.
Your help is highly appreciated
Kave
After two weeks of intense research, this blog couldn't put it better together:
http://blogs.msdn.com/b/dphill/archive/2009/08/17/prism-and-net-ria-services.aspx
There're nice Quick Start templates for Prism, I found it at blog http://blogs.msdn.com/b/dphill so it looks quite nice, I used it also created RIA Service library so everything now is separated:
1) WEb project
2) Ria Service on web
3) generated RiaService client code as separate and shared assembly and it is used by modules. that's it.

add reference to Silverlight project from other non silverlight project

I have Silverlight application using NHibernate as a ORM. I have projects for Data(mapp and entities), data access and Silverlight. I want to add to SL project reference to data access to execute methods, but SL can only get reference from other SL project.
How can I omit it? If I host data access project on WCF I could reference WCF to SL?
Please help ! :)
Yes, you can expose your data access assembly as a bunch of WCF services and then call them from the SL application.
There is also another way - make a Silverlight class library, and then add new linked files to it - those linked files being the class files from your data access assembly.
Here is a previous answer that explains the linking, although you should note that because your data access classes will now being using the Silverlight runtime you may not have access to all the System namespaces that you want (although you can pick and choose what files you want to add to the new project, and refactor the ones that don't work because of this).

Silverlight and n-Tier Development - -How is it done?

I've asked several questions on Silverlight the last day or two (I have no experience with it), and I've had some high-level questions answered. I have another high-level question. How is N-Tier development done with Silverlight? What I am considering is a browser based UI and then a c# back-end containing all the business logic and database code. How would a Silverlight client application communicate with such a back-end sitting on another server? Would it be done via Web service calls, WCF or something else? What is standard practice?
Thanks!
For the projects I've worked on. Typical practice is Silverlight providing a client and then communicating back to the back-end via WCF services.
The business logic is then spread/duplicated across the client and the backend.
You'll want to be looking at the WCF RIA Services for this. In combination with Entity Framework this will approach the sort of thing you need.
The Entity Framework creates model that you can extend and include some business logic.
The Domain Services then allow you to expose access to the model and any other range of operations you need via WCF.
The tooling that RIA Services adds to the Visual Studio will dynamically create in the Silverlight application the client side of this Domain service. There is even a provision for you create C# source that is shared by both by both Silverlight and the server code.
If its Silverlight 3 RIA is a better choice to work with. AnthonyWJones has pointed it right, There is a provision to have a shared Source between Client and Server usually Entities code should be shared in both Client and Server to get full advantage of RIA validation and other stuff.

Silverlight 3 Ria Services reference

I have a Silverlight project where functionality is segregated across multiple Silverlight libraries due to the size and complexity of the application. I am having problems figuring what is the best way to decouple the RIA Domain Service that gets generated from the Website project. I need to be able to access data from the other libraries as they will be loaded dynamically into the main Silverlight application as needed.
I ended up taking the code that gets generated by Visual Studio in the Generated_Code directory of the main Silverlight application and creating multiple Silverlight libraries to separate the Ria DomainContext, the authentication service, entities, and other Domain services that we had written. I then extracted interfaces for the DomainContext, etc and put them in their own library. Using Microsoft's Unity Framework for Silverlight I was then able to decouple all my modules from the main project. All my modules now use the interfaces. There is one IoC container in the main application where I register all of the classes that implement the interfaces and they get injected into the pages as they are instantiated. Not that compliated after all. The only thing to remember is to leave the EnableClientAccess attribute on the Domain Services classes in the server but remove the ASP.Net server project link from the main Silverlight application. I read that they are planning to make this easier in the final release of Ria services/Silverlight 3 since other people have complained about the tight coupling created by the current setup.

Silverlight databinding

I have to bind sql table to one of the grid in my silverlight page.
I have seen all the examples in web using wcf services or web services for databinding.
Can i use datalayer dll (regular way of datalayer classes) to bind data to silverlight pages.
Anyone please suggest a good article on this.I am used to the regular way of devolopment like datalayer as dll.
Is this possible in silverlight?If this is possible why system.data dll's are missing from the project.?
Thanks
SNA
System.Data.dlls are missing from Silverlight because Silverlight is a subset of .Net designed to run in a browser - and browsers don't usually have databases available! For this reason you usually have to create custom objects and return these through a WCF service.
Scott Guthrie's tutorial might be helpful as a guide to building Data Driven silverlight applciations.
Looking a few months into the future, you'll soon be able to use .Net RIA Services (Rich Internet Applications) for this kind of thing. Here's a link to the preview

Resources