This is my first go at LINQ to SQL. I create my dbml in the designer using a SQL Server Express database. I create a stored procedure called StoredProcedure1, which I also dragged into the dbml. Then I wrote up some code to test if I could update some of the fields. The problem is that no updates occur to the database, but I see the changes when the data is bound to a DataGrid. I have no idea why it's not working or what I am doing wrong. Here is the code:
DataClasses1DataContext data = new DataClasses1DataContext();
List<StoredProcedure1Result> result = new List<StoredProcedure1Result>(data.StoredProcedure1());
int i = 0;
foreach (StoredProcedure1Result r in result)
{
r.TestField = "A" + i.ToString();
i++;
}
// to see what has changed, set break point on next line
var changeSet = data.GetChangeSet();
// submit changes and show result in datagrid
data.SubmitChanges();
dataGrid.ItemsSource = result;
The stored procedure just grabs all of the records from a table:
USE [E:\test\test.MDF]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[StoredProcedure1]
AS
SELECT * FROM TEST_TABLE
RETURN