Linq to SQL使用sdf文件的异常(exception with Linq to SQL using sdf file)

编程入门 行业动态 更新时间:2024-10-28 02:22:45
Linq to SQL使用sdf文件的异常(exception with Linq to SQL using sdf file)

我已经建立了一个SDF本地数据库文件的项目,并试图使用LINQ To SQL(“.dbml”)文件来访问它。 我已经使用了由sdf文件提供的连接字符串,并且可以实例化对象而不出现问题:

thisDataContext = new MyDataContext(GetConnectionString());

但是,每当我尝试访问它的任何信息,例如

var collection = (from MyObject p in thisDataContext.MyTable select p);

我得到的错误 -

“表名无效[令牌行号(如已知)= 2,令牌行偏移量(如已知)= 14,表名= Person]”

我正在使用Visual Studio 2008 SP1 .Net 3.5和SQL 2008 CE。

我收集了类似SQL 2005 CE发布的一个类似问题,并发布了一个修补程序,但我认为修复程序在发布之前会在此版本中得到修复。

有谁知道这个的修复?

谢谢

I've set up a project with an SDF local database file and am trying to access it using an LINQ To SQL (".dbml") file. I have used the connection string provided by the sdf file and can instanciate the object with out a problem:

thisDataContext = new MyDataContext(GetConnectionString());

However, whenever i try to access any information from it eg

var collection = (from MyObject p in thisDataContext.MyTable select p);

I get the error -

"The table name is not valid. [ Token line number (if known) = 2,Token line offset (if known) = 14,Table name = Person ]"

I am using Visual Studio 2008 SP1 .Net 3.5 and SQL 2008 CE.

I gather something similar happened for SQL 2005 CE and a Hotfix was released, but i would have thought the fix would have been fixed in this version before release.

Does anyone know the fix for this?

Thanks

最满意答案

摆脱Linq to Sql创建的对象的Table属性中的“dbo”

例如:

[Table(Name="dbo.Orders")] class Order { }

将其更改为:

[Table(Name="Orders")] class Order { }

Get rid of the "dbo" in the Table attributes on the objects created by Linq to Sql

e.g.:

[Table(Name="dbo.Orders")] class Order { }

Change that to:

[Table(Name="Orders")] class Order { }

更多推荐

本文发布于:2023-08-07 22:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   文件   SQL   Linq   sdf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!