views:

1050

answers:

1

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?

+7  A: 

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).

Steven Robbins
that did explain a lot but why doesn't it show me entities in XML format? It just says DEFAULT table1. I even used config.SetEntitySetAccessRule("table1", EntitySetRights.All);
jdiaz
Also if there is no primary key set on the table how do I know which property to set as DataServiceKey?
jdiaz