Linq to SQL and SQL Server Compact Error: "There was an error parsing the query."
I created a SQL server compact database (MyDatabase.sdf), and populated it with some data. I then ran SQLMetal.exe and generated a linq to sql class (MyDatabase.mdf)
Now I'm trying to select all records from a table with a relatively straightforward select, and I get the error:
"There was an error parsing the query. [ Token line number = 3,Token line offset = 67,Token in error = MAX]"
Here is my select code:
public IEnumerable<Item> ListItems()
{
MyDatabase db_m = new MyDatabase("c:\mydatabase.sdf");
return this.db_m.TestTable.Select(test => new Item()
{
ID = test.ID,
Name = test.Name,
RequestData = test.Req开发者_开发百科uestData != null ? test.RequestData.ToString() : null,
Url = new System.Uri(test.Uri)
}.AsEnumerable();
}
I've read that Linq to SQL works with Sql Compact, is there some other configuration I need to do?
Could it be an errant NVARCHAR(MAX)? I think I've seen an error like this before with sql compact edition, and as I recall it had to do with the fact that sql compact edition doesn't support the NVARCHAR(MAX) datatype. This is also maybe why you see the "token in error = MAX" message in the exception?
Why do you need to do the conversion on RequestData? What does your class look like? Can you just set it like this?
RequestData = test.RequestData
I also tried the approach of using a SQLMetal for a SQL Server compact edition in a Winforms app for Linq-to-sql . After some problems i skipped the Linq-to-SQL Approach and went for the Linq-To-Entities approach. The syntax is like 99% the same for the query's i'm doing so ;-)
Also, when using the edmx designer, it's possible to easy update , delete and add tables.(with drag drop or Right-Click equivalent in the designer.)
精彩评论