Code sample: V5 Implementation Example: IACEntityObjectContext


C# public

/// <summary>
/// For the implementation of a custom Entity-Framework-Context you have to implement IACEntityObjectContext.
/// Use gip.core.datamodel.ACObjectContextHelper as a Helper-Class for implementing the IACEntityObjectContext-Members.
/// Declare the ACClassInfo-Attributeclass with "Global.ACKinds.TACDBAManager". After starting iPlus with "Ctrl-Key + Login-Button", 
/// this new Entity-Framework-Context-Class will appear in the iPlus development environment in the Variobatch-Tree.
/// </summary>
/// <seealso cref="mycompany.package.datamodel.MyCompanyEntities" />
/// <seealso cref="gip.core.datamodel.IACEntityObjectContext" />
/// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
[ACClassInfo("mycompany.erp", "en{'Database application'}de{'Datenbank Anwendung'}", Global.ACKinds.TACDBAManager, Global.ACStorableTypes.NotStorable, false, false)]
public partial class MyCompanyDB : ExampleV5Context, IACEntityObjectContext, INotifyPropertyChanged
{
    private ACObjectContextHelper _ObjectContextHelper;

    public MyCompanyDB()
        : base(EntityObjectExtension.DbContextOptions<ExampleV5Context>(ConnectionString))
    {
        _ObjectContextHelper = new ACObjectContextHelper(this);
    }

    /// <summary>
    /// Saves all changes in this MyCompanyDB-Context as well as in the iPlus-Context
    /// If ContextIPlus is not seperate  (Property IsSeperateIPlusContext == false / ContextIPlus == Database.GlobalDatabase) then SaveChanges will not be invoked for the global database.
    /// If you wan't that, then you have to pass an new iPlus-Context-Instance to the constructor of the MyCompanyDB-Context!
    /// UNSAFE. Use QueryLock_1X000 outside for Custom-Database-Context as well as for the seperate iPlus-Context
    /// </summary>
    /// <returns></returns>
    [ACMethodInfo("", "", 9999)]
    public MsgWithDetails ACSaveChanges(bool autoSaveContextIPlus = true, bool acceptAllChangesOnSuccess = true, bool validationOff = false, bool writeUpdateInfo = true)
    {
        MsgWithDetails result = _ObjectContextHelper.ACSaveChanges(autoSaveContextIPlus, acceptAllChangesOnSuccess, validationOff, writeUpdateInfo);
        if (result == null)
        {
            if (ACChangesExecuted != null)
                ACChangesExecuted.Invoke(this, new ACChangesEventArgs(ACChangesEventArgs.ACChangesType.ACSaveChanges, true));
        }
        else
        {
            if (ACChangesExecuted != null)
                ACChangesExecuted.Invoke(this, new ACChangesEventArgs(ACChangesEventArgs.ACChangesType.ACSaveChanges, false));
        }
        return result;
    }

    // ... Implement all other members of IACEntityObjectContext by reusing ACObjectContextHelper.
}

Modifier: Mario Žitković / Modified:24.07.2023 12:36