如果我包含计算列,LINQ to SQL 不会更新
我正在使用以下 LINQ 代码填充 DataGrid:
Dim myClients = From p In dc.Persons _
Select p
我可以导航我的 DataGrid,进行更改,然后单击一个调用“
dc.SubmitChanges()
所有这些工作正常”并更新 SQL Server 的按钮。
然后我想添加一个附加列来显示基于函数计算的年龄。我使用以下代码创建了一个 PersonAge 列并且它起作用了。
Dim myClients = From p In dc.Persons _
Select New With {p.PersonID, _
p.PersonName, _
p.PersonGender, _
.PersonAge = CalcCurrentAge(p.PersonDOB, p.PersonFirstContactDate, p.PersonFirstContactAge) _
}
但是,我注意到我无法再成功地将任何更新保存回 SQL。
所以我的问题是,如何利用第一个正确保存更新的 LINQ 代码的简单性,并将其与包含 PersonAge 列的第二个 LINQ 代码混合,以创建具有计算年龄列的可更新 DataGrid?
I am populating a DataGrid with the following LINQ code :
Dim myClients = From p In dc.Persons _
Select p
I can navigate my DataGrid, make changes and then click on a button that calls
dc.SubmitChanges()
All of this works well and updates SQL Server.
I then wanted to add a single additional column that would display a calculated age based on a Function. I used the following code to create a PersonAge column and it worked.
Dim myClients = From p In dc.Persons _
Select New With {p.PersonID, _
p.PersonName, _
p.PersonGender, _
.PersonAge = CalcCurrentAge(p.PersonDOB, p.PersonFirstContactDate, p.PersonFirstContactAge) _
}
However, I noticed that I can no longer successfully save any updates back to SQL.
So my question is, how can I take the simplicity of the first LINQ code which saves updates correctly, and mix it with the second LINQ code which includes the PersonAge column to create an updatable DataGrid with a calculated age column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 DataGrid 中而不是在 Linq 语句中对数据列进行计算。
http://www.dotnetjohn.com/articles.aspx?articleid=18
Make your calculation for your data column in your DataGrid, rather than in the Linq statement.
http://www.dotnetjohn.com/articles.aspx?articleid=18