Question

I am encountering a weird error when using linq-to-sql with ado.net data services. I have a simple silverlight application that connects to a remote database. I first added the linq-to-sql class and dragged a table onto the designer. Then I added a ADO.NET Data Service, updated the DataService reference to point to the L2S Data context.

Compiled with no problems.

When I open the service in IE I immediately get an error so I add the following attribute to the data service:

[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]

This brings up the detailed error message:

The exception message is 'On data context type 'DataClasses1DataContext', there is a top IQueryable property 'table1' 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

this happens to any database table I use in the L2S designer!

What is this error and why am I getting it?

Was it helpful?

Solution

You'll need to decorate your classes with the DataServiceKey attribute.

More details on Marc's blog here, and an MSDN blog here (the latter talks about many to many relationships, but it covers the DatServiceKey attribute).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top