I’ve got an odata wcf service and it looks like InitializeService is not being called…
The code looks like:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyDataService : DataService<MyContext>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config.UseVerboseErrors = true;
}
// see http://romiller.com/2010/07/19/ef-ctp4-tips-tricks-wcf-data-service-on-dbcontext/
protected override AzureAppContext CreateDataSource()
{
var ctx = base.CreateDataSource();
// Disable proxy object creation.
ctx.Configuration.ProxyCreationEnabled = false;
return ctx;
}
}
When this runs I get an exception reported like:
The server encountered an error processing the request. The exception
message is ‘On data context type ‘MyContext’, there is a top
IQueryable property ‘MyEntities’ whose element type is not an entity
type. Make sure that the IQueryable property is of entity type or
specify the IgnoreProperties attribute on the data context type to
ignore this property.’. See server logs for more details
In this case, MyEntities is an EntityFramework Code First DBSet.
If I place [IgnoreProperties("MyEntities")] on the context, then the error is thrown on the second property set instead.
Key I think: If I put a breakpoint in the InitializeService method then it doesn’t look like it’s being called.
Really not sure what is happening right now…
Sean helped identify the correct answer in the comments above.
Basically what had happened was that when I imported the project, then stylecop adjusted my key names from EntityID to EntityId.
Within the SQL EF layer this was OK – because I had mappings set up for the keys. However, within the oData Service it was looking for names ending in “ID” (case sensitive) and when it didn’t find them it barfed without explanation – not making it easy to debug!