Entity structure cannot read new data until the request is completed

I am creating a new project

    public int RegisterUser(string userName, string password)
    {
        var model = new User();

        model.UserName = userName;

        var salt = this.saltProvider.StringSalt();
        model.Salt = salt;

        model.Password = this.encryptionSerivce.Hash(password, options => options.WithStringSalt(salt));

        this.ValidateUser(model);

        this.users.Create(model);
        this.users.Save();

        return model.UserId;
    }

Where this.users.Create looks like this:

    public void Create(T entity)
    {
        this.dbSet.Add(entity);
    }

And save:

    public void Save()
    {
        this.dbContext.SaveChanges();
    }

My problem: after the call, the Save()changes are still in the local property: Debug

So, when I try to get only the added entity (for example this.users.Fetch(usr => usr.UserName == "Just added user name") , I get null.

My sample looks like this:

    public IEnumerable<T> Fetch(Expression<Func<T, bool>> predicate)
    {
        return this.dbSet.Where(predicate);
    }

Which is ridiculous, after the request is completed, the data is placed in db: db result

I can access int in the following request. What am I doing wrong?

Why can't I access recently added users right after calling SaveChanges () in DbContext?

+3
source share
1 answer

SaveChanges() Dbcontext.

, this.dbSet.Where(predicate) , , . Dbcontext,

SaveChanges(false), , , , .

0

All Articles