Building infrastructure to support one declaration of domain model for use with EF and RIA Services

I’ve been working on a way to declare a domain model on the server, to be used on both the server and on the Silverlight client through RIA services. Believe me when I say that this has been no easy task!

I tried to implement a single shared IDataRepository interface to both the client and server by marking the filename as .shared.cs. The data access methods would use a syntax similar to the following: repo.Get(string[] includeRelatedTables, Action<IQueryable> results), so when the data has been retrieved, it calls the callback with the results. With Silverlight, there is no synchronous database communication, so this syntax is the only one that works. However, that callback method won’t work when using the domain model with MVC… I can’t return a ViewResult to the anonymous function inside.

Another way of doing this would be to declare virtual methods that, on each side (client EF/server RIA) implements its own way of getting the data. Another better solution would be to declare these functions as Func<IQueryable> properties that can be get or set. However, I would run into the same problem as MVC on the server side, where the virtual method or Func would require me to return the results from the data source, and I can’t return from within an anonymous function… so, with this method, I’ve hit a brick wall.

I guess it’s time to install the Async CTP and see if I can make this work without using callbacks. I know projects like CSLA have this covered, but I want to create (or find a good) solution that works right away with my EF entities and RIA entities. The Async CTP should allow me to write my async data call methods like I would with RIA services, so I should be able to get rid of all of the callbacks and have both interfaces return the list of objects directly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s