Linq to SQL 和 SQL Server Compact 错误:“解析查询时出错。”
我创建了一个 SQL Server 紧凑型数据库 (MyDatabase.sdf),并在其中填充了一些数据。然后我运行 SQLMetal.exe 并生成一个 linq to sql 类 (MyDatabase.mdf)
现在我尝试使用相对简单的选择从表中选择所有记录,但出现错误:
“解析查询时出错。[令牌行号 = 3,令牌行偏移量 = 67,错误令牌 = MAX]”
这是我的选择代码:
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.RequestData != null ? test.RequestData.ToString() : null,
Url = new System.Uri(test.Uri)
}.AsEnumerable();
}
我已经读到Linq to SQL可以与Sql Compact一起使用,是吗?我需要做一些其他配置吗?
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.RequestData != 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它可能是一个错误的 NVARCHAR(MAX) 吗?我想我以前在 sql 紧凑版中见过这样的错误,我记得它与 sql 紧凑版不支持 NVARCHAR(MAX) 数据类型有关。这也许也是您在异常中看到“token in error = MAX”消息的原因?
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?
为什么需要对RequestData进行转换?你的班级是什么样的?就这样设置可以吗?
Why do you need to do the conversion on RequestData? What does your class look like? Can you just set it like this?
我还尝试了在 Winforms 应用程序中使用 SQLMetal 作为 Linq-to-sql 的 SQL Server 紧凑版的方法
。
在遇到一些问题后,我跳过了 Linq-to-SQL 方法,转而采用 Linq-To-Entities 方法。对于我这样做的查询来说,语法有 99% 相同;-)
另外,当使用 edmx 设计器时,可以轻松更新、删除和添加表。(在设计器中使用拖放或右键单击等效操作.)
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.)