Reputation: 6830
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.
Upvotes: 4
Views: 4277
Reputation: 3999
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.
Upvotes: 1
Reputation: 364249
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.
Upvotes: 2
Reputation: 754388
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:
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 collectionsIf you want to be able to insert and update data, you also need:
IUpdatable
interface on your "data context" to enable change tracking and handling of CUD operationsUpvotes: 2