Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET Data Services with Linq-to-SQL

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?

like image 578
jdiaz Avatar asked Mar 06 '09 08:03

jdiaz


People also ask

Can you use LINQ in SQL?

LINQ to SQL supports all the key capabilities you would expect as a SQL developer. You can query for information, and insert, update, and delete information from tables.

Is LINQ converted to SQL?

LINQ to SQL translates the queries you write into equivalent SQL queries and sends them to the server for processing. More specifically, your application uses the LINQ to SQL API to request query execution. The LINQ to SQL provider then transforms the query into SQL text and delegates execution to the ADO provider.

Is LINQ to SQL still used?

LINQ to SQL was the first object-relational mapping technology released by Microsoft. It works well in basic scenarios and continues to be supported in Visual Studio, but it's no longer under active development.

What you can do with LINQ to SQL?

When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language.


1 Answers

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

like image 79
Steven Robbins Avatar answered Nov 15 '22 22:11

Steven Robbins