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

Created Unassigned: Can't select an entity not committed [1224]

$
0
0
Hello, I found a small 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 codeInserted = InsertInstance();
ReadInstance(codeInserted);
}
public string InsertInstance() {
var code = "A";
UnitOfWork.Repository<EntitySetA>().Insert(new EntitySetA(){
Code = code
});
return code;
}
public void ReadInstance(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 "InsertInstance" that creates an entity and inserts it into the repository (without calling SaveChanges), and then another method "ReadInstance" that tries to find this entity by selecting it through the code returned by "InsertInstance".
However, when "ReadInstane" 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 by "InsertInstance", I need to simply pass the "codeInserted", 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?

P.S.: when I debug the repository, I can find the instance created inside _dbSet.Local when .Select is called, however, for some reason it's ignored and it doesn't return at all

Viewing all articles
Browse latest Browse all 1539

Trending Articles



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