Is doing
context.Single(x => x.Id == id);
exactly the same as
context.Find(new[] { id });
in the entity framework?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No.
Findchecks 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.Singlealways 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
Findreturnsnullif the object is neither in the context nor in the database.Singlethrows an exception if it isn’t found in the database.You mean:
context.SomeEntitySet.Find(id)andcontext.SomeEntitySet.Single(x => x.Id == id), I guess.