I am quite new to Entity Framework, and still struggling to solve it.So many different examples and explanations that i can't figure out what to do ?
I have a few questions :
In my current application I used a pattern which consist of :
For each from , I am declaring a NEW Unit Of Work .So when I make a Savechanges, only the related items are affected.
For complex business logics , I am writing my methods inside the Repository for each class For example :
However recently I found out that by Entity Framework 6.0 :
So the questions are :
First of all trying to treat your DbContext as singleton object is a bad idea, because you can't manage transactions in your operations. you have to instantiate your DbContext per operation.
Second, try to separate your "Data layer concerns" from your "Business concerns". for example :
One method for : Remove one item from one inventory location , move it to another location and then decrease the quantity at the old location
I think you are writing your repository methods per use case which is not a data layer concern. your repositories are only need to know about persisting and retrieving objects. in another way your repository methods are just CRUD methods. Your business layer will use this methods to perform business logic.