0

How we select data from SDF (webmatrix) database in visual studio with Linq just like we can with northwind, like this:?

// Northwnd inherits from System.Data.Linq.DataContext.
Northwnd nw = new Northwnd(@"northwnd.mdf");
// or, if you are not using SQL Server Express
// Northwnd nw = new Northwnd("Database=Northwind;Server=server_name;Integrated Security=SSPI");

var companyNameQuery =
    from cust in nw.Customers
    where cust.City == "London"
    select cust.CompanyName;

foreach (var customer in companyNameQuery)
{
    Console.WriteLine(customer);
}

Ref: http://msdn.microsoft.com/en-us/library/bb399398.aspx

please thank you for your help.

Arrow
  • 2,784
  • 8
  • 38
  • 61
  • '.sdf' is for SQL Server Compact Edition databases. WebMatrix is an IDE. Are you saying you created your SQLCE database in WebMatrix? – Tieson T. May 23 '12 at 22:21
  • I sure am. And I imported the website into Visual Studio Ultimate and am continuing from within Visual Studio now, @TiesonT. – Arrow May 24 '12 at 11:25

1 Answers1

1

I don't believe that Linq To SQL is officially supported with SQL Server CE 4.0, although it appears you can get it working. Microsoft's recommended approach is to use the Entity Framework.

I've written a couple of articles on using EF with SQL Server CE in WebMatrix. One covers the Code First approach, and the other looks at a database first approach.

Mike Brind
  • 28,238
  • 6
  • 56
  • 88