I am doing several insert commands before doing SaveChanges.
Is there a way to query the attached entities (that I inserted right now before the SaveChanges) in order to check whether a specific record was added or updated?
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.
Yes there is a way.
ObjectContextinstance offers property calledObjectStateManger.ObjectStateManagermanages all attached entities and it knows their state:If you need to get all modified or added entities you can use:
You can further use
OfTypeto select only entities of some type. You can also use this logicSaveChangesas described many times on Stack Overflow – for example here.