【发布时间】:2010-03-18 19:11:18
【问题描述】:
我刚开始在 Windows 窗体应用程序中使用 Linq to 实体,但我不理解一种看起来如此简单的行为。
如果我在下面键入代码,我会在我的 dataGridView 中获得只读记录
Dim x = From n in Table1 _
Select n.FirstName, n.LastName, N.Department
DataGridView1.DataSource = x
但如果我输入以下代码,我的 dataGridView 中会出现可编辑的行
Dim x = From n in Table1 _
Select n
DataGridView1.DataSource = x
所以,基本上如果我指定要选择的列名并将数据绑定到我的 DataGridView1,这些行是只读的,但如果我没有指定列名和数据绑定到 DataGridView,这些行是可编辑的,我不明白为什么.
【问题讨论】:
-
嗯,是的,匿名类型是不可变的。你期待什么?
-
根据文档,不在 VB.NET 中。 (我现在没有坐在编译器前。)
-
在 VB.NET 中,它们是,嗯,两者都是:visualstudiomagazine.com/articles/2007/10/01/…
-
嗯,是的,我的回答中包含更多细节。 :/ 好文章。我找了又找,肯定错过了。
标签: linq-to-entities