Reputation: 66882
I'm trying to get an odata demo up and running at the moment, but I'm seeing this error:
'On data context type 'TweetPicContext', there is a top IQueryable property 'Users' 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.
The annoying thing is that my code is pretty much a cut and paste of an existing project - but obviously something is going wrong...
Looking at previous questions/answers the common answer seems to be the DataServiceKey
attribute - but I'm already using that.
Anyone got any ideas where I'm going wrong?
This is my data context:
public class TweetPicContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Picture> Pictures { get; set; }
}
This is my user data class:
[DataServiceKey("UserID")]
public class User
{
[Key]
public int UserID { get; set; }
public string Name { get; set; }
public string TwitterHandle { get; set; }
public string TwitterIconUrl { get; set; }
public int TwitterId { get; set; }
public string TwitterAuthorizationToken { get; set; }
public string TwitterAuthorizationTokenSecret { get; set; }
public DateTime DateJoinedUtc { get; set; }
public string UniqueDeviceToken { get; set; }
public virtual ICollection<Picture> Pictures { get; set; }
public User()
{
DateJoinedUtc = DateTime.UtcNow;
UniqueDeviceToken = Guid.NewGuid().ToString("N");
}
}
This is my user service:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class TweetPicOData : DataService<TweetPicContext>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("Users", EntitySetRights.AllRead);
config.SetEntitySetAccessRule("Pictures", EntitySetRights.AllRead);
config.UseVerboseErrors = true;
}
// see http://romiller.com/2010/07/19/ef-ctp4-tips-tricks-wcf-data-service-on-dbcontext/
protected override TweetPicContext CreateDataSource()
{
var ctx = base.CreateDataSource();
// Disable proxy object creation.
ctx.Configuration.ProxyCreationEnabled = false;
return ctx;
}
}
Upvotes: 3
Views: 6213
Reputation: 31
I had the same issue as @Trevor and solved it the same way at first. Then I found this thread and discovered that my service project was referring to Microsoft.Data.Services.Client, while the project with my entities was referring to System.Data.Services.Client. By changing the reference in my entity project I got it working.
Upvotes: 2
Reputation: 4860
I had this same issue. The object I was using as the data source was in a separate library and for some reason, when I duplicated the class as a .cs file in my website, everything worked fine. I assume it was because of version issues.
Upvotes: 3
Reputation: 4336
WCF Data Services 5.0 added the support necessary to invoke the EF provider when DbContext is used. If you are using DbContext with an earlier version of WCF Data Services, the stack will fall back to using the Reflection provider rather than the EF provider. This will result in behavior similar to what you are describing.
Upgrading to a version of WCF Data Services 5.0 or greater should resolve the issue. Since version 5.0, we have been distributing bits via NuGet: http://www.nuget.org/packages/Microsoft.Data.Services.Client.
HTH, Mark
Upvotes: 3