views:

186

answers:

1

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?

+3  A: 

Make your calculation for your data column in your DataGrid, rather than in the Linq statement.

http://www.dotnetjohn.com/articles.aspx?articleid=18

Robert Harvey
Hi Robert, I take it from your reply that if want to update using LINQ, I cannot have any calulated columns? It wasn't just a case of me coding my LINQ incorrectly then?
Mitch
I'm guessing that the calculated column in the Linq statement doesn't match up with any corresponding column in the database, and so the whole update fails.
Robert Harvey