Advanced programming


Database programming is carried out using the entity framework. Entity framework 4 from the "System.Data.Objects"-namespace (previos iplus Version V4) is supported and Entity Framework Core 8 (newer Version V5 on gitHub).

Before you start programming, you should familiarize yourself with the functionality of the entity framework and the change tracking mechanism!

This knowledge is urgently needed in order to be able to program high-performance and memory-optimized applications (see also https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/performance-considerations). So here are a few important basic rules to keep in mind:

  1. Avoid long-term contexts. Instantiate database contexts with the using statement so that the memory is then freed.
  2. If you still need long-term database contexts, always secure the queries with thread locks. It is best to use the gip.core.datamodel.ACMonitor for this. This monitor class is able to preventively display possible deadlocks during the development phase and to resolve deadlocks that occur during runtime.
  3. Do not create long-term database contexts yourself, but using the "gip.core.datamodel.ACObjectContextManager.GetOrCreateContext()" method. The ACObjectContextManager is a static helper class that is used to manage long-term contexts. So that you can use it, your database model must implement the IACEntityObjectContext interface. You can find out more in the chapter "Extending iPlus with your own database models".
  4. Avoid change tracking if possible. e.g. for data that are only read.
  5. If data is only used for display or reading, use the select query with the new operator to create your own anonymous or known classes that are not "System.Data.Objects.DataClasses.EntityObject". These can also be provided with the ACClassInfo and ACPropertyInfo attributes for presentation on the surface and rights management.
  6. If change tracking is required and EntityObject instances are materialized, then try to load all the necessary relations with the include() extension method with the first query so that lazy loading is avoided.
  7. Use precompiled queries.

 

You will learn in the following sections

  • Which database contexts iPlus already provides and how they can be used
  • how to add your own database models and entity classes,
  • and how to program storable queries.