这是LINQ-to-SQL的示例吗? [英] Is this an example of LINQ-to-SQL?
问题描述
我用SQL CE数据库制作了一个WPF小应用程序.
我用LINQ构建了以下代码来从数据库中获取数据,这非常容易.所以我认为这必须是LINQ-to-SQL".
然后,我做了添加项目"并添加了"LINQ-to-SQL类" .dbml文件,将表拖到了对象关系设计器"上,但是它说:所选对象使用了不受支持的数据提供程序." >
因此,我质疑以下代码是否实际上是LINQ-to-SQL,因为它确实允许我从我的SQL CE数据库文件访问数据,但是正式似乎不支持"LINQ-to-SQL" SQL CE.
那么下面的"LINQ-to-SQL"是否正确?
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Windows;
namespace TestLinq22
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
MainDB db = new MainDB(@"Data Source=App_Data\Main.sdf");
var customers = from c in db.Customers
select new {c.FirstName, c.LastName};
TheListBox.ItemsSource = customers;
}
}
[Database(Name = "MainDB")]
public class MainDB : DataContext
{
public MainDB(string connection) : base(connection) { }
public Table<Customers> Customers;
}
[Table(Name = "Customers")]
public class Customers
{
[Column(DbType = "varchar(100)")]
public string FirstName;
[Column(DbType = "varchar(100)")]
public string LastName;
}
}
此msdn文章指出,尽管LINQ to SQL运行时支持sdf,但设计器不支持sdf.
引用:
- LINQ to SQL运行时和SQLMetal命令行工具支持SQL Server Compact 3.5.
- 对象关系设计器不支持SQL Server Compact 3.5.
I made a little WPF application with a SQL CE database.
I built the following code with LINQ to get data out of the database, which was surprisingly easy. So I thought "this must be LINQ-to-SQL".
Then I did "add item" and added a "LINQ-to-SQL classes" .dbml file, dragged my table onto the Object Relational Designer but it said, "The selected object uses an unsupported data provider."
So then I questioned whether or not the following code actually is LINQ-to-SQL, since it indeed allows me to access data from my SQL CE database file, yet officially "LINQ-to-SQL" seems to be unsupported for SQL CE.
So is the following "LINQ-to-SQL" or not?
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Windows;
namespace TestLinq22
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
MainDB db = new MainDB(@"Data Source=App_Data\Main.sdf");
var customers = from c in db.Customers
select new {c.FirstName, c.LastName};
TheListBox.ItemsSource = customers;
}
}
[Database(Name = "MainDB")]
public class MainDB : DataContext
{
public MainDB(string connection) : base(connection) { }
public Table<Customers> Customers;
}
[Table(Name = "Customers")]
public class Customers
{
[Column(DbType = "varchar(100)")]
public string FirstName;
[Column(DbType = "varchar(100)")]
public string LastName;
}
}
This msdn article notes that while sdf is supported by the LINQ to SQL runtime, it is not supported by the designer.
To Quote:
- The LINQ to SQL runtime and the SQLMetal command-line tool support SQL Server Compact 3.5.
- The Object Relational Designer does not support SQL Server Compact 3.5.
这篇关于这是LINQ-to-SQL的示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!