4

I have recently created a pretty robust API built around Entity Framework's DbContext. I am using a lot of metadata programming and taking advantage of the fact that I can get my data with a call like DbContext.Set(typeof(Customer)). Only, in my API I do not know at compile time what type I will be passing to the Set method. This is working very well with EntityFramework and I would like to add another layer abstraction and have it work with both EntityFramework or DataServiceContext. So, I really have two questions.

Firstly, and more specifically, is there a DataServiceContext (i.e. odata/wcf) equivalent to the DbContext.Set(type) method?

Secondly, and more generally, is there a good resource that compares the APIs provided by DbContext with DataServiceContext?

Phillip Scott Givens
  • 5,256
  • 4
  • 32
  • 54

2 Answers2

1

EntityFramework and DataServices client API should not be mixed. Even though they look similar they are not. DbSet represents entity set. I don't think there is a strong contract around entity sets in DataServiceContext. Instead the name of the entity set is passed to methods that need to know this (e.g. look at DataServiceContext.AddObject() or DataServiceContext.CreateQuery() methods) as strings. In some sense it makes it much easier to program the DataServiceContext dynamically. On the other hand you still need to know what is on the other side of the pipe (i.e. the server). As said above WCF Data Services and EntityFramework are different technologies (even though they can work together) and their APIs, though similar, serve different purposes. Therefore comparing them would be like comparing apples to oranges.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • 1
    I do not find this answer helpful. Yes, one is an ORM and the other is a OData client, but both technologies allow me to query, insert and update data. Therefore, there is enough similarity to warrant a comparison. I am sorry if you disagree but I think that you are confusing the what (WCF vs ORM) with the how (API). – Phillip Scott Givens Jan 19 '13 at 23:24
0

The DbContext API in the client side is not the same from DbContext on server side. The main goal is to expose the data and model, which can be done pretty well. I think you may be overengeneering your app, since WCF Data Services can provide enough funcionalities.

Here is a link from Ladislav Mrnka, who is very good at entity framework, he shows how you could expose your robust api with WCF Data Services.

Implement WCF Data Service using the Repository Pattern

Community
  • 1
  • 1