Is doing
context.Single(x => x.Id == id);
exactly the same as
context.Find(new[] { id });
in the entity framework?
Is doing
context.Single(x => x.Id == id);
exactly the same as
context.Find(new[] { id });
in the entity framework?
No. Find
checks first if the object is already loaded into the context. If yes it just returns this object. If no it queries the entity from the database. Single
always queries the object from the database. If it is already in the context it gets updated with the values from the DB. (Edit: The last sentence is wrong, see comments!)
Also Find
returns null
if the object is neither in the context nor in the database. Single
throws an exception if it isn't found in the database.
You mean: context.SomeEntitySet.Find(id)
and context.SomeEntitySet.Single(x => x.Id == id)
, I guess.