Home >Database >Mysql Tutorial >Can LINQ Perform Direct SQL Updates Without Selecting Data First?
When dealing directly with SQL, you can generate update commands with conditionals without running a select statement. In LINQ, the common pattern involves selecting entities, modifying them, and submitting the changes. However, is it possible to perform a direct update using LINQ and deferred execution without transmitting data to the client?
The provided LINQ query attempts to perform a direct update, but it includes a select clause. While LINQ has all the information needed to generate an update command, there is no "set" keyword equivalent in LINQ.
Solution:
To create direct update statements using LINQ-to-SQL:
Foo foo = new Foo { FooId = fooId };
context.Foos.Attach(foo);
foo.Name = "test";
context.SubmitChanges();
Note:
The above is the detailed content of Can LINQ Perform Direct SQL Updates Without Selecting Data First?. For more information, please follow other related articles on the PHP Chinese website!