【问题标题】:How to select from WebMatrix-database in Visual Studio with Linq如何使用 Linq 从 Visual Studio 中的 WebMatrix 数据库中进行选择
【发布时间】:2012-05-23 21:41:44
【问题描述】:

我们如何使用 Linq 从 Visual Studio 中的 SDF (webmatrix) 数据库中选择数据,就像使用北风一样,像这样:?

// 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);
}

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

感谢您的帮助。

【问题讨论】:

  • '.sdf' 适用于 SQL Server Compact Edition 数据库。 WebMatrix 是一个 IDE。您是说您在 WebMatrix 中创建了 SQLCE 数据库?
  • 我确定。我将网站导入 Visual Studio Ultimate 并从 Visual Studio 中继续,@TiesonT。

标签: c# .net visual-studio-2010 razor webmatrix


【解决方案1】:

我不相信 SQL Server CE 4.0 正式支持 Linq To SQL,尽管it appears you can get it working。 Microsoft 推荐的方法是使用实​​体框架。

我写了几篇关于在 WebMatrix 中将 EF 与 SQL Server CE 结合使用的文章。一个覆盖Code First approach,另一个覆盖looks at a database first approach

【讨论】:

  • 哦,这太棒了。谢谢@Mike,你让我开心!
  • 很棒的文章,迈克。感谢一万亿。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多