Hi all I am doing something like this -
void update(ClasstoUpdate obj)//obj is already having values to update...
{
var data= (from i in Entityobject.Clas
The simple way to update an object is fetch it, change it, and submit changes which is what you're already doing.
Another way is to attach the object, and tell the entity framework that the object is in a modified state.
A third way is to update the object by constructing an SQL string that updates the object directly in the database without fetching it. However I wouldn't recommend doing this.
A side note: remember to check for null in your function. If you know the return value of FirstOrDefault
will never be null then you should use First
instead. You might also want to consider using Single
instead of First
.