0

I'm using Entity Framework in version 6.2.0.
And I have a simple question about this framework.
Is it possible to insert/add record, and select this same record before using SaveChanges function??

I'll try to represent this by simple code:

// prepare and add new record
User u = new User();
Context.Users.Add(u);
Context.Entry(u).State = EntityState.Added;

var y = (from x in Context.Users).FirstOrDefault(); // return null
// i expected that, in here i found new Created User 

Context.SaveChanges();

var y = (from x in Context.Ussers).FirstOrDefault(); // return != null

I'm doing this, because i'm going to join a created record with a few other tables.

tk421
  • 5,775
  • 6
  • 23
  • 34
neuser
  • 107
  • 13
  • This answer has options depending on what EF version you're on: https://stackoverflow.com/a/6426326/84206 – AaronLS Mar 09 '18 at 19:18

1 Answers1

0

DbSet has a Local property that represents a local view of the set (including Added, Unchanged and Modified entities). You can see Entity Framework Local Data documentation for more information.

Jose Alonso Monge
  • 1,014
  • 1
  • 16
  • 29