An easy way to update an object is to select it, modify it, and submit the changes that you already make.
Another way is to attach the object and inform the infrastructure of the entity that the object is in an altered state.
The third way is to update the object by building an SQL string that updates the object directly in the database without getting it. However, I would not recommend doing this.
Note: Remember to check the null value in your function. If you know that the return value of FirstOrDefault will never be zero, then you should use First . You may also consider using Single instead of First .
source share