I am using the .NET entity framework 4.1 with a code approach to effectively solve the following problem, it is simplified here.
- There is a database table with tens of thousands of records.
- Several users of my program should be able to
- View the table (total) in GridRow, which implies that you must load the entire table.
- Change the values โโof any random string, the changes are frequent, but not necessarily saved immediately. He expected different users to change different lines, but this is not always the case. Some loss of changes is allowed, as users are more likely to update the same rows to the same values.
- Add new lines if necessary.
Sounds simple enough. My initial approach was to use a long instance of DbContext . This DbContext was supposed to track changes for objects, so when SaveChanges() is called, most of the work is done automatically. However, many noted that this is not an optimal solution in the long run , especially here . I'm still not sure if I understand the reasons, and I don't see that there is a unit of work in my script. The user chooses himself when to save changes, and let them say that the client always wins for simplicity. It is also important to note that objects that were not affected do not overwrite any data in the database.
Another approach would be to track changes manually or use change tracking objects for me, however, I am not very good at such methods, and I would welcome a push in the right direction.
What is the right way to solve this problem?
I understand that this question is a little desirable, but think of it as more fundamental. I lack a fundamental understanding of how to solve this class of problems. It seems to me that the long life of DbContext is the right way, but knowledgeable people tell me differently, which leads me to confusion and inaccurate questions.
EDIT1 Another confusion is the existence of the Local property of the DbSet<> object. He invites me to use a long context, as another user posted here .
Gleno source share