Entity Framework: Re-finding objects recently added to context

前端 未结 7 706
感情败类
感情败类 2020-11-30 03:53

I am using the entity framework and I\'m having a problem with \"re-finding\" objects I just created... basically it goes like this:

string theId = \"someId         


        
7条回答
  •  青春惊慌失措
    2020-11-30 04:09

    The newly added object is in the local DataSource, since it's not persisted yet in the database,

    so you may say:

    EntityObject search = ents.EntityObject.FirstOrDefault(o => o.Id == theId) ??
                          ents.EntityObject.Local.FirstOrDefault(o => o.Id == theId);
    

提交回复
热议问题