Task. There is a base of films (the film has various fields, in this context it does not matter which ones). In particular, the film has a collection of genres. That is, there is still a table with genres and a table for the connection of the film and the many-to-many genre.
I make a WPF application. The base is ruled by a separate class library. To protect the UI project from EF, I decided to make a separate adapter class ( first question, is it necessary or is it bad practice? ). The adapter is instance. The adapter creates a data context. It turns out that within the scope of the application I have one instance of the adapter (and therefore one instance of the data context). Question two, is this normal? After all, if every time to create a new context, the application will be very long to think. With this approach, I still have a problem with saving data. Well, for example, I opened 2 forms, one for editing information about the film, the other for editing a set of genres. And if I click Save in the form of editing genres (that is, I send the _context.SaveChanges () command), then the changes that I made while editing the film (they were made in the same context) will be entered into the database. Question three, how to work with the data so that this does not happen? And anyway, I can't figure out how to screw it all humanly on MVVM. So far, I am doing govnodic. :( In general, this was the fourth question. How to screw it all on MVVM? In addition, I need a paginal output. So far, only the context.EntitySet.Skip(a).Take(b) method comes to mind. And here is also the question Is this correct? Will such an approach cause a request for all previous values to skip values before returning the necessary set to me?
UPD:
My research led me to what
The adapter is still needed, if only to protect the project UI from working with the Entity Framework.
The context is first created for a long time and makes the first request for a long time (at least the same request to the same network). Each time it uses data from the cache.
Thanks to question 2, question 3 was dropped. But there was a new question. I am making a change to the data in the context instance. Data is saved. I change them from the outside, then I get everything in the same context and it does not pull up third-party changes. That is, it shows the old data. How to tell him to make a new request?
Questions 4 and 5 remained open.
To receive data page by page for MSSQL for me was not that problematic, but not very pleasant (I had to throw a query in the form of text into the procedure), or the query took quite a long time (with large amounts of data). I'm currently working with SQLite. In general, the question of optimization and all that. If someone is sure that EF in this case adequately asks for the page data, please unsubscribe.