0

I'm new to EF i want to execute this sql command using only EF and linq :

I looked on internet but most of the questions are related to old versions of EF

Update Foo set foo.Name ="Modified"
where Foo.id = 6

Is this possible ?

0

1 Answer 1

1

This is as simple as following:

var foos = Foo.Where(f => f.id == 6).ToList();
foos.ForEach(f => f.Name = "Modified");

context.SaveChanges();
Sign up to request clarification or add additional context in comments.

2 Comments

is this the only way to do it ? cant we do something to avoid hitting the database multiple times ( read + updates )
Here you hit the database once for a query and once for save data. This is the proper approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.