Dealing with DBContext lifecycle

GreekTreatGreekTreat Member ✭✭

I find it strange there isn't a good tutorial on a standard way to set up EF Core with SQLLite to be used properly in Xamarin, I've started using DI to have all my repositories instatiated but I have them currently having the same instance of DBContext. I thought this was recommended(but I may be wrong). I thought this way because we don't want to open the sqllite file everytime we need it and what if multiple thread are updating the DB at the same time. One issue that came up when trying this approach out is that if I need to update an object in the db that was already updated before I can't use _databaseContext.ProgramCode.Update(programCode); I need to pull that object with the key then do a member wise copy to all its properties. Is this the only correct approach ? is there a good sample to show this. It is very important to make sure I have a solid DB layer in the app.

Sign In or Register to comment.