ADO.NET Data Services with Linq-to-SQL

2019-06-15 02:34发布

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?

1条回答
Luminary・发光体
2楼-- · 2019-06-15 02:59

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

查看更多
登录 后发表回答