views:

60

answers:

2

I'd like to develope simple set of controls to display many sort of data and be useful in normal silverlight application and can be used in ASP.NET MVC2 application. Right now i have no idea how to link those tehnologies, but this isn't my concern right now - i just heard it is possible and i'll find out how to do that...

Right now i'd like to know how can i use my Model's classes in such SIlverlight class library. I've generated POCO classes in EF4.0 for ASP.NET MVC2 application. Everything works great, but now i'd like to use some of those classes - create silverlight's controls, some ViewModel classes and fill my controls with data passed from my Model, used in ASP.MVC's app, through ViewModel.

Everything should be tested in any simple silverlight's app and at the end i'd like to be able use this class library in silverlight app and in ASP.MVC 2 website...

A: 

Silverlight it's own runtime and in general you cannot mix normal .NET assemblies and Silverlight assemblies.

However, one option is to share the source code by linking the same source file to two projects that compile to the different runtimes.

Another option is to use WCF RIA Services where Visual Studio will code generate your model classes in the Silverlight project and there are also options for sharing code between tiers. You will also get a service to operate on the objects from Silverlight. The service can be built on top of EF4.0 with very little code.

Finally, Silverlight 4 and .NET 4 are in some cases able to share assemblies if certain criteria are met. See Stack Overflow question named Silverlight 4 Assembly Sharing Problem.

Martin Liversage
A: 

What you need to do is use shared code.

you do this by adding an existing file to a project. In the add file dialog there is a arrow on the button that exposes the add as link option.

the point of this is that you cna have 2 projects which target the different CLR's but contain the same code and namespace references ... you can leverage these to have code that works on both versions of the CLR very simply.

Its really quite powerful. I have one set of tests that can target both versions.

Of course you are limited to the set of common functionality but that is implicitly part of your requirements anyway.

You cna even pass the objects over a service and have them deserialise nicley into the other CLR. Kinda suprising how well you can use the symetry

I am currently using this for aproject and am achieving what you want and after a few hours of playing with really suprisingly painless.

regards

John Nicholas