ADO.NET Data Services with Linq-to-SQL

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 14:40:04

问题


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:


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



来源:https://stackoverflow.com/questions/618027/ado-net-data-services-with-linq-to-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!