Context submitchanges is not updating the database

In addition to updating existing rows in the database, LINQ to SQL obviously also enables you to insert and delete data.

You can accomplish this by adding/removing data objects from the Data Context's table collections, and by then calling the Submit Changes() method.

Submit Changes() above, LINQ to SQL will dynamically construct and execute a SQL "UPDATE" statement that will update the two product property values we modified above.

For example, I could write the below code to update the price and # of units in stock of the "Chai" product in the database: When I call northwind.For example, I could write the below LINQ expression to retrieve a single Product object by searching on the Product name: I could then write the LINQ query expression below to retrieve all products from the database that haven't yet had an order placed for them, and which also cost more than 0: Note above how I am using the "Order Details" association for each product as part of the query to only retrieve those products that have not had any orders placed for them.When we perform queries and retrieve objects like the product instances above, LINQ to SQL will by default keep track of any changes or updates we later make to these objects.As I covered in Part 3 of this blog series, we can easily use LINQ syntax expressions to query and retrieve data from our database using this Northwind Data Context class.LINQ to SQL will then automatically translate these LINQ query expressions to the appropriate SQL code to execute at runtime.

Leave a Reply