Entity Framework, heavy load and large graph of objects

I have a WPF project that works with a local database of projects. The local database is later synchronized with the server. Each project has several systems, and each of them has several "tags". The tag has a product, and the product consists of several materials in a fairly advanced structure. A simple structure would be like this:

  • Project
    • Systems
      • Tags
        • Products
          • Material 1
          • Material 2
          • Material 3
        • Tag requirements
      • System requirements

I have two problems that I must solve right now.

  • When loading a project, I need to download the entire project from the database and work with the local copy until the user saves it. When I try to download the download, it will take a lot of time, and I found that you do not need to include a lot, as this is bad for performance. Is there any good practice how should I load a deep structure into memory?

  • The reason I need to load it into memory is that the user can work with the copy, and then in a certain place can save it in the database. I have several calculation functions that depend on another part of the tree. My conclusions allowed me to think that I need to publish the whole project (or at least the system) at the business level, since all the data can be edited locally (memory)

, ? , ( ) memorydb . , , .

, , ,

+4
2

.Include N: M Entity Framework , , .

. , . ( ) .

- , .

() ORM, NHibernate, " ", EntityFramework .

+1

, , Include, .

:

scarRevision = db.ScarRevisions
.Include(s => s.Author)
.Include(s => s.Scar.Author)
.Include(s => s.Scar.LockedBy)
.Include(s => s.Scar.Part)
.Include(s => s.Scar.Supplier)
.Include(s => s.ScarGeneralSection.GeneralSectionAttachments)
.Include(s => s.ScarGeneralSection.SupplierContacts.Select(sc => sc.Contact))
// on and on and on...
.FirstOrDefault(s => s.Scar.ScarNumber == scarNumber && s.RevisionNumber == revisionNumber);

:

scarRevision = db.ScarRevisions
.Include(s => s.Author)
.Include(s => s.Scar.Author)
.FirstOrDefault(s => s.Scar.ScarNumber == scarNumber && s.RevisionNumber == revisionNumber);

scarRevision = db.ScarRevisions
.Include(s => s.Scar.LockedBy)
.Include(s => s.Scar.Part)
.FirstOrDefault(s => s.Scar.ScarNumber == scarNumber && s.RevisionNumber == revisionNumber);

scarRevision = db.ScarRevisions
.Include(s => s.Scar.Supplier)
.FirstOrDefault(s => s.Scar.ScarNumber == scarNumber && s.RevisionNumber == revisionNumber);

, 20 3. , 10 , .

0

Source: https://habr.com/ru/post/1534631/


All Articles