4
votes

I want to expose legacy .net code via WCF Data Services. But without using Entity Framework anywhere. Basically I currently populate all my models from db once every X hours and dump these models in cache. The current web services pull all the info from this cache. I now have to convert all of this to WCF Data Services, primarily to support OData protocol.

What is the simplest and quickest way out (again, no entity framework)

Below is an example of how my model currently looks like:

public class Country
{
    public string CountryCode {get; set;}
    public string CountryName {get; set;}
    public List<State> ListOfStates {get; set;}
}

public class State
{
    public string StateCode {get; set;}
    public string StateName {get; set;}
}

Thanks in advance.

3

3 Answers

2
votes

You need to use reflection provider instead of Entity framework provider - custom context class exposed in WCF Data Service. Just be aware that reflection provider by default expose only read only data. If you need to update data through your OData service you will also have to implement IUpdateble interface on your context class.

2
votes

It's not black magic - but a bit of work.

See this WCF Data Services Advanced Topics article which shows how you could use e.g. Subsonic for your ORM.

Basically, the steps involved are:

  • you need to expose IQueryable<T> collections for all your classes - you could do this by having some kind of a DataModel or DataContext class that contains all those collections

If you want to be able to insert and update data, you also need:

  • to implement the IUpdatable interface on your "data context" to enable change tracking and handling of CUD operations
1
votes

I don't want to advertise myself actually, but your problem is the same situation we had here at work. We've taken over the original toolkit developed by Jonathan Carter for mapping WCF DataServices to whatever you want them to be.

Try taking a look at http://wcfdstoolkit.codeplex.com/ and see if this solves your problem. The documentation is available through links to Jonathan's blog on how to setup & use the toolkit. But I recommend to download the september release branch, to ensure you have all bug fixes in it that I already solved.