Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exception with Linq to SQL using sdf file

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

like image 383
Ben Avatar asked Dec 28 '22 23:12

Ben


1 Answers

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
{

}
like image 140
BFree Avatar answered Jan 13 '23 03:01

BFree