views:

584

answers:

3

Last try to get an answer on this.

I have a simple ASP.NET app which uses Hibernate for data access. GUI can call methods on Customer object like "CalculateTotalSumOfOrders()". Lazy loading (even though it's not optimal) will work for me, and when Orders and OrderLines collections are referenced in the domain objects, they will get automatically fetched from the database.

Now let's assume I am rewriting the same very app to Silverlight because it looks better than ASP.NET. I am NO longer able to do lazy loading or data access, because Silverlight client runs in the browser. How can I solve this without thinking too much about what kind of service to use to get data into the Silverlight client?

A: 

You're trying to take a server-side app that interacts with your database and does lazy loading, and convert it into a client-side app without a lot of work? Sorry, it's just not going to work. What you need is a major rearchitecting of your application.

Sorry...

McWafflestix
That's okay because I'm quite early there. How would you rearchitect it to support both ASP.NET, silverlight and windows clients with minimal overhead?
badbadboy
+1  A: 

Your best bet for supporting all of those platforms is to use a web service. There are many different flavors that you can choose from, .NET 2.0 Web Services (ASMX), WCF, REST, if you are using Silverlight, you may want to consider using WCF + LINQ to SQL which is demonstrated here. That combination can also be used in ASP.NET (if running on .NET 3.5) and Windows Desktop Apps (again .NET 3.5).

Also an open source project called InterLinq might be interesting to you, basically it allows you to build LINQ to SQL queries on the client side, and then transmit them through WCF to a server that executes the query and returns the result. That can be found here. I have experimented with it in the past and it works quite well.

Jason Miesionczek
+1  A: 

One option that would support Silverlight and Windows clients would be the new ADO.NET Data Services in .NET 3.5 SP1. These are a set of services that expose your database schema through a WCF interface. You can then retrieve the data from Silverlight or a Windows Client using a WCF client.

As @McWafflestix has said, you won't be able to do lazy loading any more, but in my opinion that's a good thing because retrieving data is now a much more "expensive" operation.

Jeremy Wiebe