2012年1月19日 上午 10:56
I have an entity model.
I am using DbContext generator to create the entities.
I have a WCF Data Service which exposes these entities.
I have a silverlight project with a service reference to the WCF Data Service.
If, from the silverlight, I use a query like this:
var qry = from l in svc.Locations.Expand("Attractions") select l;
I can see a correctly formatted OData query in fiddler however, the Attractions list is not populated in the returned feed.
If I do exactly the same but, instead of using DbContext I use the default entity generator, I again see an identical OData query in fiddler, but the response does include the Attractions.
Every example I have found for DbContext uses Include to load navigation properties instead of Expand. As far as I can tell, Include is not valid in an OData query.
Any ideas why the service doesn't return the "expanded" entities?
Is it something to do with the
this.Configuration.ProxyCreationEnabled = false;
line of code I have in the DbContext sub class on the server?Any help greatly appreciated.
2012年1月29日 上午 10:44版主
Please take a look at this article http://social.technet.microsoft.com/wiki/contents/articles/5234.aspx.
In section #5 it shows how to expose DbContext through WCF Data Services. The main point is that the service has to be DataService<ObjectContext> and not DataService<DbContext>.
But even without that I would expect the query to either fail or return correct data. Did you try to debug the service to see if the data is actually available where you expect it?
Vitek Karas [MSFT]
2012年1月30日 上午 11:12
Thanks for posting the link to that article, Vitek.
A sentance in it which I found very useful , is :
"...the current released version of WCF Data Services does not recognize DbContext as an Entity Framework provider, so you need to manually provide the base ObjectContext class to the data service..."
Would've been nice to have discovered that whilst searching the web.
I am applying the article to our project, currently I am recieving an error when attempting to view the service in a browser:
The exception message is 'Value cannot be null. Parameter name: key'. See server logs for more details.
..at System.Collections.Generic.Dictionary`2.FindEntry(TKey key) at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.Services.Providers.ObjectContextServiceProvider.PopulateMetadata....
Trace also shows a "configuration evaluation context not found" warning at the Open Servicehost stage.
"...Did you try to debug the service to see if the data is actually available where you expect it?..."
This is my first project with WCF; other than the microsoft service trace viewer and a few things in code (IncludeExceptionDetailInFaults, UseVerboseErrors, override HandleException) I don't really know how to debug a WCF service, certainly not to the extent of checking if data is where I expect it.
Thanks again, will have some time this afternnon to look into the errors being thrown and will come back with an update.