Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

New Post: how to select an inserted entity before calling savechanges

$
0
0
Hello, I'm currently using this generic repository implementation and I really like it, however, I found a little issue which I would to know if is it by design or if I might be doing something wrong, basically I have a code a little bit like this:
public class CA {
    protected IUnitOfWork UnitOfWork{get; private set;}
    public CA() {
        //instantiates the unit of work here
    }
    public void MA() {
        var code = MB();
        MC(code);
    }
    public string MB() {
        var code = "A";
        UnitOfWork.Repository<EntitySetA>().Insert(new EntitySetA(){
            Code = code
        });
        return code;
    }
    public void MC(string code) {
        var entity = UnitOfWork.Repository<EntitySetA>().Query(x=>x.Code == code).Select();
        if ( entity != null ) {
            //never reaches this line
        }
    }
}
In other words, I have a method A that creates an entity and inserts it into the repository (without calling SaveChanges), and then another method B that tries to find this entity by selecting it through the code returned by method A.
However, when the method B queries the repository, nothing is returned, obviously if I call UnitOfWork.SaveChanges() and then try to select, the object is found, unfortunately I have a scenario which instead of passing the instance created on method A, I need to simply pass the code, and now I'm struggling trying to figure out what I might be doing wrong.

To sum things up, should the entity be found when I query for it even though SaveChanges didn't get called, if so, is there anything else I must do to accomplish this?

Thanks in advance!

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>