using System;
using System.Collections.Generic;
using IWS5.DatabaseAccess.IwsDataModels;
using Microsoft.EntityFrameworkCore;

namespace IWS5.DatabaseAccess.IwsDataContext;

public partial class GreenfieldPd2015Context : DbContext
{
    public const string ConnectionStringName = "GreenfieldPD";
    public GreenfieldPd2015Context(DbContextOptions<GreenfieldPd2015Context> options)
        : base(options)
    {
    }

    public virtual DbSet<AtassigmentType> AtassigmentTypes { get; set; }

    public virtual DbSet<AtbarcodeFont> AtbarcodeFonts { get; set; }

    public virtual DbSet<Atbutton> Atbuttons { get; set; }

    public virtual DbSet<Atcode> Atcodes { get; set; }

    public virtual DbSet<Atconnection> Atconnections { get; set; }

    public virtual DbSet<AtconnectionType> AtconnectionTypes { get; set; }

    public virtual DbSet<AtconvertDefinition> AtconvertDefinitions { get; set; }

    public virtual DbSet<AtconvertEvent> AtconvertEvents { get; set; }

    public virtual DbSet<AtdCftemplate> AtdCftemplates { get; set; }

    public virtual DbSet<AtdDefaultTemplate> AtdDefaultTemplates { get; set; }

    public virtual DbSet<AtdEmarkDocTemplate> AtdEmarkDocTemplates { get; set; }

    public virtual DbSet<AtdTestDate> AtdTestDates { get; set; }

    public virtual DbSet<AtdTestInteger> AtdTestIntegers { get; set; }

    public virtual DbSet<AtdTestMixed> AtdTestMixeds { get; set; }

    public virtual DbSet<AtdocumenctReviewStatus> AtdocumenctReviewStatuses { get; set; }

    public virtual DbSet<Atdocument> Atdocuments { get; set; }

    public virtual DbSet<AtdocumentArc> AtdocumentArcs { get; set; }

    public virtual DbSet<AtdocumentCabinet> AtdocumentCabinets { get; set; }

    public virtual DbSet<AtdocumentCabinetDef> AtdocumentCabinetDefs { get; set; }

    public virtual DbSet<AtdocumentCabinetFiledType> AtdocumentCabinetFiledTypes { get; set; }

    public virtual DbSet<AtenterpriseConnection> AtenterpriseConnections { get; set; }

    public virtual DbSet<Aterror> Aterrors { get; set; }

    public virtual DbSet<AteventDefinition> AteventDefinitions { get; set; }

    public virtual DbSet<AteventTriggerDefinition> AteventTriggerDefinitions { get; set; }

    public virtual DbSet<AteventTriggerTemplate> AteventTriggerTemplates { get; set; }

    public virtual DbSet<AteventType> AteventTypes { get; set; }

    public virtual DbSet<AtexceptionNote> AtexceptionNotes { get; set; }

    public virtual DbSet<AtexportDefinition> AtexportDefinitions { get; set; }

    public virtual DbSet<AtexportEvent> AtexportEvents { get; set; }

    public virtual DbSet<AtexportFlagTxt> AtexportFlagTxts { get; set; }

    public virtual DbSet<AtexportLocation> AtexportLocations { get; set; }

    public virtual DbSet<AtexportType> AtexportTypes { get; set; }

    public virtual DbSet<AtexternalTrackingDefinition> AtexternalTrackingDefinitions { get; set; }

    public virtual DbSet<AtexternalTrackingSourceType> AtexternalTrackingSourceTypes { get; set; }

    public virtual DbSet<Atfaq> Atfaqs { get; set; }

    public virtual DbSet<AtfieldDefinition> AtfieldDefinitions { get; set; }

    public virtual DbSet<AtfieldInstanceDate> AtfieldInstanceDates { get; set; }

    public virtual DbSet<AtfieldInstanceNumber> AtfieldInstanceNumbers { get; set; }

    public virtual DbSet<AtfieldInstanceString> AtfieldInstanceStrings { get; set; }

    public virtual DbSet<AtfieldInstanceOption> AtfieldInstanceOptions { get; set; }

    public virtual DbSet<Atform> Atforms { get; set; }

    public virtual DbSet<Athistory> Athistories { get; set; }

    public virtual DbSet<AthistoryEvent> AthistoryEvents { get; set; }

    public virtual DbSet<AthistoryParameter> AthistoryParameters { get; set; }

    public virtual DbSet<AtimportDocumentType> AtimportDocumentTypes { get; set; }

    public virtual DbSet<AtimporterConfiguration> AtimporterConfigurations { get; set; }

    public virtual DbSet<AtinboxEvent> AtinboxEvents { get; set; }

    public virtual DbSet<Atlabel> Atlabels { get; set; }

    public virtual DbSet<Atlink> Atlinks { get; set; }

    public virtual DbSet<Atmail> Atmails { get; set; }

    public virtual DbSet<Atmaintenance> Atmaintenances { get; set; }

    public virtual DbSet<AtmergeOrder> AtmergeOrders { get; set; }

    public virtual DbSet<Atnote> Atnotes { get; set; }

    public virtual DbSet<AtpendingWorkItemReference> AtpendingWorkItemReferences { get; set; }

    public virtual DbSet<AtprocessDefinition> AtprocessDefinitions { get; set; }

    public virtual DbSet<AtprocessDocumentTemplateRight> AtprocessDocumentTemplateRights { get; set; }

    public virtual DbSet<AtprocessGroup> AtprocessGroups { get; set; }

    public virtual DbSet<AtprocessImportRule> AtprocessImportRules { get; set; }

    public virtual DbSet<Atqueue> Atqueues { get; set; }

    public virtual DbSet<Atreport> Atreports { get; set; }

    public virtual DbSet<Atright> Atrights { get; set; }

    public virtual DbSet<AtrightAllowRight> AtrightAllowRights { get; set; }

    public virtual DbSet<AtrightObjectType> AtrightObjectTypes { get; set; }

    public virtual DbSet<Atrule> Atrules { get; set; }

    public virtual DbSet<AtrunStatusType> AtrunStatusTypes { get; set; }

    public virtual DbSet<AtsavedSearch> AtsavedSearches { get; set; }

    public virtual DbSet<AtscheduleInstanceOld> AtscheduleInstanceOlds { get; set; }

    public virtual DbSet<AtscheduleStatusType> AtscheduleStatusTypes { get; set; }

    public virtual DbSet<AtscheduleType> AtscheduleTypes { get; set; }

    public virtual DbSet<AtscheduledItem> AtscheduledItems { get; set; }

    public virtual DbSet<AtscheduledTask> AtscheduledTasks { get; set; }

    public virtual DbSet<Atscript> Atscripts { get; set; }

    public virtual DbSet<Atsearch> Atsearches { get; set; }

    public virtual DbSet<AtsearchCriterion> AtsearchCriteria { get; set; }

    public virtual DbSet<AtsearchDisplayField> AtsearchDisplayFields { get; set; }

    public virtual DbSet<AtsearchParam> AtsearchParams { get; set; }

    public virtual DbSet<AtsearchRegistration> AtsearchRegistrations { get; set; }

    public virtual DbSet<AtsearchTypeDefinition> AtsearchTypeDefinitions { get; set; }

    public virtual DbSet<Atserver> Atservers { get; set; }

    public virtual DbSet<AtsetDatum> AtsetData { get; set; }

    public virtual DbSet<Atsplit> Atsplits { get; set; }

    public virtual DbSet<Atstack> Atstacks { get; set; }

    public virtual DbSet<Atsystem> Atsystems { get; set; }

    public virtual DbSet<AtsystemParameter> AtsystemParameters { get; set; }

    public virtual DbSet<AttaskActionType> AttaskActionTypes { get; set; }

    public virtual DbSet<AttaskDefinition> AttaskDefinitions { get; set; }

    public virtual DbSet<AttaskInstance> AttaskInstances { get; set; }

    public virtual DbSet<AttaskType> AttaskTypes { get; set; }

    public virtual DbSet<Attemplate> Attemplates { get; set; }

    public virtual DbSet<AttemplateType> AttemplateTypes { get; set; }

    public virtual DbSet<Attimer> Attimers { get; set; }

    public virtual DbSet<AttrackingDefinition> AttrackingDefinitions { get; set; }

    public virtual DbSet<AttrackingDefinitionTemplate> AttrackingDefinitionTemplates { get; set; }

    public virtual DbSet<AttrackingRecord> AttrackingRecords { get; set; }

    public virtual DbSet<AttrackingRecordArc> AttrackingRecordArcs { get; set; }

    public virtual DbSet<AttriggerAction> AttriggerActions { get; set; }

    public virtual DbSet<AttriggerHook> AttriggerHooks { get; set; }

    public virtual DbSet<Atuser> Atusers { get; set; }

    public virtual DbSet<AtuserProperty> AtuserProperties { get; set; }

    public virtual DbSet<AtuserPropertyDefinition> AtuserPropertyDefinitions { get; set; }

    public virtual DbSet<AtuserReport> AtuserReports { get; set; }

    public virtual DbSet<AtuserSystemVariable> AtuserSystemVariables { get; set; }

    public virtual DbSet<AtvariableDefinition> AtvariableDefinitions { get; set; }

    public virtual DbSet<AtvariableInstanceBinaryBlob> AtvariableInstanceBinaryBlobs { get; set; }

    public virtual DbSet<AtvariableInstanceDate> AtvariableInstanceDates { get; set; }

    public virtual DbSet<AtvariableInstanceNumber> AtvariableInstanceNumbers { get; set; }

    public virtual DbSet<AtvariableInstanceString> AtvariableInstanceStrings { get; set; }

    public virtual DbSet<AtvariableInstanceTextBlob> AtvariableInstanceTextBlobs { get; set; }

    public virtual DbSet<AtworkItem> AtworkItems { get; set; }

    public virtual DbSet<AtworkItemArc> AtworkItemArcs { get; set; }

    public virtual DbSet<AtworkItemReference> AtworkItemReferences { get; set; }

    public virtual DbSet<AtworkItemReferenceArc> AtworkItemReferenceArcs { get; set; }

    public virtual DbSet<AtworkItemTransmit> AtworkItemTransmits { get; set; }

    public virtual DbSet<AtxmlHierarchy> AtxmlHierarchies { get; set; }

    public virtual DbSet<AtxmlHierarchyDefinition> AtxmlHierarchyDefinitions { get; set; }

    public virtual DbSet<AtxmlTemplateDefinition> AtxmlTemplateDefinitions { get; set; }

    public virtual DbSet<Postxml> Postxmls { get; set; }

    public virtual DbSet<Redirect> Redirects { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AtassigmentType>(entity =>
        {
            entity.HasKey(e => e.Id)
                .HasName("PK_AtAssigmentType")
                .IsClustered(false);
        });

        modelBuilder.Entity<Atbutton>(entity =>
        {
            entity.HasOne(d => d.Event).WithMany(p => p.Atbuttons)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATButton_ATEvent");

            entity.HasOne(d => d.Queue).WithMany(p => p.Atbuttons)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATButton_ATQueue");
        });

        modelBuilder.Entity<Atconnection>(entity =>
        {
            entity.HasOne(d => d.TypeNavigation).WithMany(p => p.Atconnections)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATConnection_ATConnectionType");
        });

        modelBuilder.Entity<AtconvertDefinition>(entity =>
        {
            entity.HasOne(d => d.BarcodesFont).WithMany(p => p.AtconvertDefinitions).HasConstraintName("FK_ATExportDefinition_BarcodesFontId");

            entity.HasOne(d => d.ExportDocType).WithMany(p => p.AtconvertDefinitionExportDocTypes).HasConstraintName("FK_ATExportDefinition_ExportDocTypeId");

            entity.HasOne(d => d.MergeOrder).WithMany(p => p.AtconvertDefinitions).HasConstraintName("FK_ATExportDefinition_MergeOrderId");

            entity.HasOne(d => d.SourceDocType).WithMany(p => p.AtconvertDefinitionSourceDocTypes).HasConstraintName("FK_ATExportDefinition_SourceDocTypeId");
        });

        modelBuilder.Entity<AtconvertEvent>(entity =>
        {
            entity.HasOne(d => d.Event).WithMany(p => p.AtconvertEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATConvertEvent_EventId");

            entity.HasOne(d => d.Template).WithMany(p => p.AtconvertEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATConvertEvent_TemplateId");
        });

        modelBuilder.Entity<AtdCftemplate>(entity =>
        {
            entity.Property(e => e.Address).HasDefaultValue("");
            entity.Property(e => e.City).HasDefaultValue("");
            entity.Property(e => e.DisasterNo).HasDefaultValue("");
            entity.Property(e => e.DocType).HasDefaultValue("");
            entity.Property(e => e.FirstName).HasDefaultValue("");
            entity.Property(e => e.LastName).HasDefaultValue("");
            entity.Property(e => e.RegId).HasDefaultValue("");
            entity.Property(e => e.State).HasDefaultValue("");
            entity.Property(e => e.Zip).HasDefaultValue("");
        });

        modelBuilder.Entity<Atdocument>(entity =>
        {
            entity.Property(e => e.LastModified).HasDefaultValueSql("(getdate())");
            entity.Property(e => e.ReviewNumber).HasDefaultValue(1);
            entity.Property(e => e.ReviewStatusId).HasDefaultValue(1);

            entity.HasOne(d => d.Cabinet).WithMany(p => p.Atdocuments)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATDocument_FK_Cabinet");

            entity.HasOne(d => d.ReviewStatus).WithMany(p => p.Atdocuments)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATDocument_FK_ReviewStatusId");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.Atdocuments)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATDocument_FK_WorkItemId");
        });

        modelBuilder.Entity<AtdocumentArc>(entity =>
        {
            entity.HasKey(e => e.DocumentId).IsClustered(false);

            entity.Property(e => e.DocumentId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtdocumentCabinet>(entity =>
        {
            entity.ToTable("ATDocumentCabinet", tb => tb.HasTrigger("ATDocumentCabinetModifiedDate"));

            entity.Property(e => e.CreateDate).HasDefaultValueSql("(getdate())");
            entity.Property(e => e.ModifyDate).HasDefaultValueSql("(getdate())");
            entity.Property(e => e.ObjectId).HasDefaultValueSql("(newid())");
            entity.Property(e => e.TemplateTypeId).HasDefaultValue(1);

            entity.HasOne(d => d.DbConnection).WithMany(p => p.AtdocumentCabinets).HasConstraintName("FK_ATDocumentCabinet_DbConnectionId");

            entity.HasOne(d => d.TemplateType).WithMany(p => p.AtdocumentCabinets)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATDocumentCabinet_TemplateTypeId");
        });

        modelBuilder.Entity<AtdocumentCabinetDef>(entity =>
        {
            entity.Property(e => e.Display).HasDefaultValue(true);
            entity.Property(e => e.ObjectId).HasDefaultValueSql("(newid())");

            entity.HasOne(d => d.Cabinet).WithMany(p => p.AtdocumentCabinetDefs)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATDocumentCabinetDef_ATDocumentCabinet");

            entity.HasOne(d => d.FieldDataTypeNavigation).WithMany(p => p.AtdocumentCabinetDefs).HasConstraintName("FK_ATDocumentCabinetDef_ATDocumentCabinetFiledType");
        });

        modelBuilder.Entity<AtenterpriseConnection>(entity =>
        {
            entity.HasKey(e => e.ConnectionName).IsClustered(false);
        });

        modelBuilder.Entity<AteventDefinition>(entity =>
        {
            entity.HasKey(e => e.EventId)
                .HasName("PK_EventDefinition")
                .IsClustered(false);

            entity.HasOne(d => d.EventType).WithMany(p => p.AteventDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATEventDefinition_ATEventType");

            entity.HasOne(d => d.JoinEvent).WithMany(p => p.InverseJoinEvent).HasConstraintName("ATEventDefinition_ATEventDefinition");

            entity.HasOne(d => d.Process).WithMany(p => p.AteventDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATEventDefinition_ATProcessDefinition");

            entity.HasOne(d => d.AssignedServer)
                .WithMany(p => p.AteventDefinitions)
                .HasForeignKey(d => d.Server)
                .HasPrincipalKey(p => p.HostName)
                .HasConstraintName("FK_ATEventDefinition_ATServer");
        });

        modelBuilder.Entity<AteventTriggerDefinition>(entity =>
        {
            entity.HasKey(e => e.Id).IsClustered(false);

            entity.HasOne(d => d.Action).WithMany(p => p.AteventTriggerDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATEventTrigger_Action");

            entity.HasOne(d => d.Hook).WithMany(p => p.AteventTriggerDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATEventTrigger_Hook");

            entity.HasOne(d => d.Process).WithMany(p => p.AteventTriggerDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATEventTrigger_ProcessDefinition");

            entity.HasOne(d => d.Template).WithMany(p => p.AteventTriggerDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATEventTrigger_Template");
        });

        modelBuilder.Entity<AteventTriggerTemplate>(entity =>
        {
            entity.HasKey(e => e.Id).IsClustered(false);

            entity.HasIndex(e => new { e.EventId, e.TemplateId }, "IX_ATEventTriggerTemplate_EventId_Order_Clustered").IsClustered();

            entity.HasOne(d => d.Event).WithMany(p => p.AteventTriggerTemplates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATEventTriggerTemplate_EventId");

            entity.HasOne(d => d.Template).WithMany(p => p.AteventTriggerTemplates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATEventTriggerTemplate_TemplateId");
        });

        modelBuilder.Entity<AtexceptionNote>(entity =>
        {
            entity.HasKey(e => e.WorkItemReferenceId).IsClustered(false);

            entity.Property(e => e.WorkItemReferenceId).ValueGeneratedNever();

            entity.HasOne(d => d.ExceptionUserNavigation).WithMany(p => p.AtexceptionNotes).HasConstraintName("ATExceptionNote_FK2");

            entity.HasOne(d => d.WorkItemReference).WithOne(p => p.AtexceptionNote)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATExceptionNote_FK1");
        });

        modelBuilder.Entity<AtexportDefinition>(entity =>
        {
            entity.HasOne(d => d.DoneFlag).WithMany(p => p.AtexportDefinitions).HasConstraintName("FK_ATExportDefinition_DoneFlag");

            entity.HasOne(d => d.ExportFileFormat).WithMany(p => p.AtexportDefinitions).HasConstraintName("FK_ATExportDefinition_ExportFileFormatId");

            entity.HasOne(d => d.ExportType).WithMany(p => p.AtexportDefinitions).HasConstraintName("FK_ATExportDefinition_ExportTypeId");

            entity.HasOne(d => d.Template).WithMany(p => p.AtexportDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATExportDefinition_TemplateId");

            entity.HasMany(d => d.ExportLocations).WithMany(p => p.ExportDefinitions)
                .UsingEntity<Dictionary<string, object>>(
                    "AtexportDefinitionExportLocation",
                    r => r.HasOne<AtexportLocation>().WithMany()
                        .HasForeignKey("ExportLocationId")
                        .HasConstraintName("FK_ATExportDefinition_ExportLocation_Location"),
                    l => l.HasOne<AtexportDefinition>().WithMany()
                        .HasForeignKey("ExportDefinitionId")
                        .HasConstraintName("FK_ATExportDefinition_ExportLocation_Definition"),
                    j =>
                    {
                        j.HasKey("ExportDefinitionId", "ExportLocationId");
                        j.ToTable("ATExportDefinition_ExportLocation");
                    });
        });

        modelBuilder.Entity<AtexportEvent>(entity =>
        {
            entity.HasOne(d => d.Event).WithMany(p => p.AtexportEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATExportEvent_EventId");

            entity.HasOne(d => d.Template).WithMany(p => p.AtexportEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATExportEvent_TemplateId");
        });

        modelBuilder.Entity<AtexternalTrackingDefinition>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_ATExternalTrackingDefinition_Id");

            entity.Property(e => e.SourceTypeId).HasDefaultValue(3);

            entity.HasOne(d => d.SourceType).WithMany(p => p.AtexternalTrackingDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATExternalTrackingDefinition_SourceTypeId");

            entity.HasOne(d => d.Template).WithMany(p => p.AtexternalTrackingDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATExternalTrackingDefinition_TemplateId");
        });

        modelBuilder.Entity<AtfieldDefinition>(entity =>
        {
            entity.HasKey(e => e.FieldId)
                .HasName("PK_FieldDefinition")
                .IsClustered(false);

            entity.Property(e => e.DataType).HasDefaultValue((byte)5);
            entity.Property(e => e.Display).HasDefaultValue(true);
            entity.Property(e => e.ObjectId).HasDefaultValueSql("(newid())");

            entity.HasOne(d => d.Process).WithMany(p => p.AtfieldDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldDefinition_ProcessDefinition");
        });

        modelBuilder.Entity<AtfieldInstanceDate>(entity =>
        {
            entity.HasKey(e => e.FieldInstanceId).IsClustered(false);

            entity.HasOne(d => d.Field).WithMany(p => p.AtfieldInstanceDates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceDate_ATFieldDefinition");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.AtfieldInstanceDates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceDate_ATWorkItem");
        });

        modelBuilder.Entity<AtfieldInstanceNumber>(entity =>
        {
            entity.HasKey(e => e.FieldInstanceId).IsClustered(false);

            entity.HasOne(d => d.Field).WithMany(p => p.AtfieldInstanceNumbers)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceNumber_ATFieldDefinition");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.AtfieldInstanceNumbers)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceNumber_ATWorkItem");
        });

        modelBuilder.Entity<AtfieldInstanceOption>(entity =>
        {
            entity.HasKey(e => e.FieldInstanceId).IsClustered(false);

            entity.HasOne(d => d.Field).WithMany(p => p.AtfieldInstanceOptions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceOption_ATFieldDefinition");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.AtfieldInstanceOptions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceOption_ATWorkItem");
        });

        modelBuilder.Entity<AtfieldInstanceString>(entity =>
        {
            entity.HasKey(e => e.FieldInstanceId).IsClustered(false);

            entity.HasOne(d => d.Field).WithMany(p => p.AtfieldInstanceStrings)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceString_ATFieldDefinition");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.AtfieldInstanceStrings)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATFieldInstanceString_ATWorkItem");
        });

        modelBuilder.Entity<Atform>(entity =>
        {
            entity.HasKey(e => new { e.FormName, e.ProcessId }).IsClustered(false);

            entity.HasOne(d => d.Process).WithMany(p => p.Atforms)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATForm_FK1");
        });

        modelBuilder.Entity<Athistory>(entity =>
        {
            entity.HasKey(e => e.HistoryId).IsClustered(false);

            entity.Property(e => e.HistoryId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AthistoryEvent>(entity =>
        {
            entity.HasKey(e => e.HistoryEventId).IsClustered(false);

            entity.Property(e => e.HistoryEventId).ValueGeneratedNever();

            entity.HasOne(d => d.History).WithMany(p => p.AthistoryEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATHistoryEvent_FK1");
        });

        modelBuilder.Entity<AthistoryParameter>(entity =>
        {
            entity.HasKey(e => e.HistoryParameterId).IsClustered(false);

            entity.Property(e => e.HistoryParameterId).ValueGeneratedNever();

            entity.HasOne(d => d.History).WithMany(p => p.AthistoryParameters)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATHistoryParameter_FK1");
        });

        modelBuilder.Entity<AtimportDocumentType>(entity =>
        {
            entity.Property(e => e.IsActive).HasDefaultValue(true);
        });

        modelBuilder.Entity<AtimporterConfiguration>(entity =>
        {
            entity.Property(e => e.CleanArchiveIntervalDays).HasDefaultValue(30);
            entity.Property(e => e.CpuUsagePercentLimit).HasDefaultValue(80);
            entity.Property(e => e.IsActive).HasDefaultValue(true);
            entity.Property(e => e.LogFileMaxSizeMb).HasDefaultValue(100);
            entity.Property(e => e.LogRetentionDays).HasDefaultValue(7);
            entity.Property(e => e.LoopPauseMinutes).HasDefaultValue(30);
            entity.Property(e => e.MaxPdfsizeMb).HasDefaultValue(20);
        });

        modelBuilder.Entity<AtinboxEvent>(entity =>
        {
            entity.HasOne(d => d.AssignmentType).WithMany(p => p.AtinboxEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATInboxEvent_ATAssignmentType");

            entity.HasOne(d => d.Event).WithMany(p => p.AtinboxEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATInboxEvent_ATEventDefinition");

            entity.HasOne(d => d.Inbox).WithMany(p => p.AtinboxEvents).HasConstraintName("FK_ATInboxEvent_ATQueue");
        });

        modelBuilder.Entity<Atlabel>(entity =>
        {
            entity.HasKey(e => e.LabelId).IsClustered(false);

            entity.Property(e => e.LabelId).ValueGeneratedNever();
        });

        modelBuilder.Entity<Atlink>(entity =>
        {
            entity.HasKey(e => new { e.ProcessId, e.FromEventId, e.ToEventId })
                .HasName("PK_Link")
                .IsClustered(false);

            entity.HasOne(d => d.FromEvent).WithMany(p => p.AtlinkFromEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATLink_FK2");

            entity.HasOne(d => d.Process).WithMany(p => p.Atlinks)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATLink_FK1");

            entity.HasOne(d => d.ToEvent).WithMany(p => p.AtlinkToEvents)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATLink_FK3");
        });

        modelBuilder.Entity<Atmail>(entity =>
        {
            entity.Property(e => e.Enable).HasDefaultValue(true);

            entity.HasOne(d => d.Connection).WithMany(p => p.Atmails).HasConstraintName("FK_ATMail_ATConnection");

            entity.HasOne(d => d.Event).WithMany(p => p.Atmails)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Event");

            entity.HasOne(d => d.Process).WithMany(p => p.Atmails)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Process");
        });

        modelBuilder.Entity<Atnote>(entity =>
        {
            entity.HasKey(e => e.NoteId).IsClustered(false);

            entity.HasOne(d => d.Document).WithMany(p => p.Atnotes).HasConstraintName("FK_ATNote_ATDocument");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.Atnotes)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATNote_ATWorkItem");
        });

        modelBuilder.Entity<AtpendingWorkItemReference>(entity =>
        {
            entity.Property(e => e.CreatedTime).HasDefaultValueSql("(getutcdate())");

            entity.HasOne(d => d.PendingWorkItemReference).WithOne(p => p.AtpendingWorkItemReference)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATPendingWorkItemReference_WorkItemReference");
        });

        modelBuilder.Entity<AtprocessDefinition>(entity =>
        {
            entity.HasKey(e => e.ProcessId)
                .HasName("PK_ProcessDefinition")
                .IsClustered(false);

            entity.Property(e => e.DefaultDocTemplate).HasDefaultValue(1);

            entity.HasOne(d => d.CreatorNavigation).WithMany(p => p.AtprocessDefinitionCreatorNavigations).HasConstraintName("ATProcessDefinition_Creator");

            entity.HasOne(d => d.DefaultDocTemplateNavigation).WithMany(p => p.AtprocessDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATProcessDefinition_ATDocumentCabinet");

            entity.HasOne(d => d.LockedByNavigation).WithMany(p => p.AtprocessDefinitionLockedByNavigations).HasConstraintName("ATProcessDefinition_LockedBy");

            entity.HasOne(d => d.ProcessGroup).WithMany(p => p.AtprocessDefinitions).HasConstraintName("ATProcessDefinition_ProcessGroupID");

            entity.HasOne(d => d.StartEvent).WithMany(p => p.AtprocessDefinitions).HasConstraintName("ATProcessDefinition_StartEventID");
        });

        modelBuilder.Entity<AtprocessDocumentTemplateRight>(entity =>
        {
            entity.HasOne(d => d.AllowRightsNavigation).WithMany(p => p.AtprocessDocumentTemplateRights)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATProcessDocumentTemplateRights_ATRightAllowRight");

            entity.HasOne(d => d.DocumentTemplateObject).WithMany(p => p.AtprocessDocumentTemplateRights)
                .HasPrincipalKey(p => p.ObjectId)
                .HasForeignKey(d => d.DocumentTemplateObjectid)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATProcessDocumentTemplateRights_ATDocumentCabinet");

            entity.HasOne(d => d.ProcessObject).WithMany(p => p.AtprocessDocumentTemplateRights)
                .HasPrincipalKey(p => p.ObjectId)
                .HasForeignKey(d => d.ProcessObjectId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATProcessDocumentTemplateRights_ATProcessDefinition");
        });

        modelBuilder.Entity<AtprocessGroup>(entity =>
        {
            entity.HasKey(e => e.ProcessGroupId).IsClustered(false);
        });

        modelBuilder.Entity<AtprocessImportRule>(entity =>
        {
            entity.HasOne(d => d.ConvertToFormat).WithMany(p => p.AtprocessImportRules).HasConstraintName("FK_ATProcessImportRule_ConvertToFormat");

            entity.HasOne(d => d.Process).WithMany(p => p.AtprocessImportRules)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATProcessImportRule_Process");
        });

        modelBuilder.Entity<Atqueue>(entity =>
        {
            entity.HasKey(e => e.Id)
                .HasName("PK_Queue")
                .IsClustered(false);

            entity.HasOne(d => d.Event).WithMany(p => p.Atqueues)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATQueue_ATEvent");

            entity.HasOne(d => d.Process).WithMany(p => p.Atqueues)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATQueue_ATProcessDefinition");
        });

        modelBuilder.Entity<Atright>(entity =>
        {
            entity.HasOne(d => d.AllowRightsNavigation).WithMany(p => p.Atrights)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATRight_ATRightAllowRight");

            entity.HasOne(d => d.ObjectTypeNavigation).WithMany(p => p.Atrights)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATRight_ATRightObjectType");

            entity.HasOne(d => d.User).WithMany(p => p.Atrights)
                .HasPrincipalKey(p => p.ObjectId)
                .HasForeignKey(d => d.UserGuid)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATRight_ATUser");
        });

        modelBuilder.Entity<AtrightAllowRight>(entity =>
        {
            entity.HasKey(e => e.Id).IsClustered(false);

            entity.Property(e => e.Id).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtrightObjectType>(entity =>
        {
            entity.HasKey(e => e.Id).IsClustered(false);
        });

        modelBuilder.Entity<AtsavedSearch>(entity =>
        {
            entity.HasKey(e => e.QueryId).IsClustered(false);

            entity.Property(e => e.QueryId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtscheduleStatusType>(entity =>
        {
            entity.Property(e => e.StatusId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtscheduledItem>(entity =>
        {
            entity.Property(e => e.CreatedAt).HasDefaultValueSql("(getutcdate())");
            entity.Property(e => e.Enabled).HasDefaultValue(true);
            entity.Property(e => e.Priority).HasDefaultValue(0);
            entity.Property(e => e.ScheduleTypeId).HasDefaultValue(1);
            entity.Property(e => e.StatusId).HasDefaultValue(1);
            entity.Property(e => e.UpdatedAt).HasDefaultValueSql("(getutcdate())");

            entity.HasOne(d => d.LastRunStatus).WithMany(p => p.AtscheduledItems).HasConstraintName("FK_ATScheduledItem_ATRunStatusType");

            entity.HasOne(d => d.ScheduleType).WithMany(p => p.AtscheduledItems)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATScheduledItem_ATScheduleType");

            entity.HasOne(d => d.Status).WithMany(p => p.AtscheduledItems)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATScheduledItem_ATScheduleStatusType");

            entity.HasOne(d => d.Server)
                .WithMany(p => p.AtscheduledItems)
                .HasForeignKey(d => d.ServerHost)
                .HasPrincipalKey(p => p.HostName)
                .HasConstraintName("FK_ATScheduledItem_ATServer");
        });

        modelBuilder.Entity<AtscheduledTask>(entity =>
        {
            entity.Property(e => e.Enabled).HasDefaultValue(true);

            entity.HasOne(d => d.OnFailureAction).WithMany(p => p.AtscheduledTaskOnFailureActions).HasConstraintName("FK_TaskAction_Failure");

            entity.HasOne(d => d.OnSuccessAction).WithMany(p => p.AtscheduledTaskOnSuccessActions).HasConstraintName("FK_TaskAction_Success");

            entity.HasOne(d => d.Schedule).WithMany(p => p.AtscheduledTasks).HasConstraintName("FK_ATScheduledTask_ATScheduledItem");

            entity.HasOne(d => d.TaskType).WithMany(p => p.AtscheduledTasks)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATScheduledTask_ATTaskType");
        });

        modelBuilder.Entity<Atscript>(entity =>
        {
            entity.HasOne(d => d.Event).WithMany().HasConstraintName("Atscript_FK2");

            entity.HasOne(d => d.Process).WithMany().HasConstraintName("Atscript_FK1");
        });

        modelBuilder.Entity<Atsearch>(entity =>
        {
            entity.HasKey(e => e.SearchId).IsClustered(false);

            entity.Property(e => e.SearchId).ValueGeneratedNever();

            entity.HasOne(d => d.SearchRegistration).WithMany(p => p.Atsearches).HasConstraintName("ATSearch_FK1");
        });

        modelBuilder.Entity<AtsearchDisplayField>(entity =>
        {
            entity.HasOne(d => d.SearchRegistration).WithMany()
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATSearchDisplayField_FK1");
        });

        modelBuilder.Entity<AtsearchRegistration>(entity =>
        {
            entity.HasKey(e => e.ObjectGuid).IsClustered(false);

            entity.Property(e => e.ObjectGuid).ValueGeneratedNever();

            entity.HasOne(d => d.ConnectionNameNavigation).WithMany(p => p.AtsearchRegistrations)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATSearchRegistration_FK1");
        });

        modelBuilder.Entity<Atserver>(entity =>
        {
            entity.HasKey(e => e.HostName).IsClustered(false);
        });

        modelBuilder.Entity<Atsplit>(entity =>
        {
            entity.HasKey(e => e.SplitWorkItemRef).IsClustered(false);

            entity.Property(e => e.SplitWorkItemRef).ValueGeneratedNever();

            entity.HasOne(d => d.JoinEvent).WithMany(p => p.Atsplits).HasConstraintName("ATSplit_FK1");

            entity.HasOne(d => d.SourceWorkItemRefNavigation).WithMany(p => p.AtsplitSourceWorkItemRefNavigations)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATSplit_FK3");

            entity.HasOne(d => d.SplitWorkItemRefNavigation).WithOne(p => p.AtsplitSplitWorkItemRefNavigation)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATSplit_FK2");
        });

        modelBuilder.Entity<Atstack>(entity =>
        {
            entity.HasKey(e => new { e.WorkItemRef, e.EventId }).IsClustered(false);

            entity.HasOne(d => d.Event).WithMany(p => p.Atstacks)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATStack_FK1");

            entity.HasOne(d => d.SubProcess).WithMany(p => p.Atstacks)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATStack_FK3");

            entity.HasOne(d => d.WorkItemRefNavigation).WithMany(p => p.Atstacks)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATStack_FK2");
        });

        modelBuilder.Entity<AtsystemParameter>(entity =>
        {
            entity.HasKey(e => e.ParamId).IsClustered(false);

            entity.Property(e => e.ParamId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AttaskDefinition>(entity =>
        {
            entity.HasKey(e => e.TaskId)
                .HasName("PK_TaskDefinition")
                .IsClustered(false);

            entity.Property(e => e.TaskId).ValueGeneratedNever();

            entity.HasOne(d => d.Event).WithMany(p => p.AttaskDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATTaskDefinition_FK1");
        });

        modelBuilder.Entity<AttaskInstance>(entity =>
        {
            entity.HasKey(e => new { e.TaskId, e.WorkItemReferenceId })
                .HasName("PK_TaskInstance")
                .IsClustered(false);

            entity.HasOne(d => d.CompletedByNavigation).WithMany(p => p.AttaskInstances).HasConstraintName("ATTaskInstance_FK3");

            entity.HasOne(d => d.Task).WithMany(p => p.AttaskInstances)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATTaskInstance_FK1");

            entity.HasOne(d => d.WorkItemReference).WithMany(p => p.AttaskInstances)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATtaskInstance_FK2");
        });

        modelBuilder.Entity<Attemplate>(entity =>
        {
            entity.HasIndex(e => new { e.ProcessId, e.DocumentCabinetId, e.TemplateTypeId }, "UQ_ATTemplates_ProcessCabinetType")
                .IsUnique()
                .HasFilter("([TemplateTypeId]<>(7))");

            entity.Property(e => e.CreateDate).HasDefaultValueSql("(getdate())");
            entity.Property(e => e.ModifyDate).HasDefaultValueSql("(getdate())");
            entity.Property(e => e.ObjectId).HasDefaultValueSql("(newid())");

            entity.HasOne(d => d.DbConnection).WithMany(p => p.Attemplates).HasConstraintName("FK_ATTemplates_DbConnectionId");

            entity.HasOne(d => d.DocumentCabinet).WithMany(p => p.Attemplates).HasConstraintName("FK_ATTemplates_DocumentCabinetId");

            entity.HasOne(d => d.Hierarchy).WithMany(p => p.Attemplates).HasConstraintName("FK_ATTemplates_HierarchyId");

            entity.HasOne(d => d.Process).WithMany(p => p.Attemplates).HasConstraintName("FK_ATTemplates_ProcessId");

            entity.HasOne(d => d.TemplateType).WithMany(p => p.Attemplates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTemplates_TemplateTypeId");
        });

        modelBuilder.Entity<Attimer>(entity =>
        {
            entity.HasOne(d => d.Event).WithMany(p => p.Attimers)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTimer_EventID");

            entity.HasOne(d => d.Process).WithMany(p => p.Attimers)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTimer_ProcessID");
        });

        modelBuilder.Entity<AttrackingDefinition>(entity =>
        {
            entity.HasOne(d => d.Event).WithMany(p => p.AttrackingDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTrackingDefinition_ATEventDefinition");

            entity.HasOne(d => d.Process).WithMany(p => p.AttrackingDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTrackingDefinition_ATProcessDefinition");
        });

        modelBuilder.Entity<AttrackingDefinitionTemplate>(entity =>
        {
            entity.HasOne(d => d.Template).WithMany(p => p.AttrackingDefinitionTemplates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTrackingDefinitionTemplates_TemplateId");

            entity.HasOne(d => d.TrackingDefinition).WithMany(p => p.AttrackingDefinitionTemplates)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTrackingDefinitionTemplates_TrackingDefinitionId");
        });

        modelBuilder.Entity<AttrackingRecord>(entity =>
        {
            entity.HasKey(e => e.Id).IsClustered(false);

            entity.HasOne(d => d.LastAction).WithMany(p => p.AttrackingRecords).HasConstraintName("FK_ATTrackingRecord_ATButton");

            entity.HasOne(d => d.TrackingDefinition).WithMany(p => p.AttrackingRecords).HasConstraintName("FK_ATTrackingRecord_ATTrackingDefinition");

            entity.HasOne(d => d.UserNameNavigation).WithMany(p => p.AttrackingRecords).HasConstraintName("FK_ATTrackingRecord_ATUser");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.AttrackingRecords)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATTrackingRecord_ATWorkItem");
        });

        modelBuilder.Entity<AttrackingRecordArc>(entity =>
        {
            entity.HasKey(e => e.TrackingRecordId).IsClustered(false);

            entity.Property(e => e.TrackingRecordId).ValueGeneratedNever();
        });

        modelBuilder.Entity<Atuser>(entity =>
        {
            entity.HasKey(e => e.UserName)
                .HasName("PK_User")
                .IsClustered(false);

            entity.HasMany(d => d.Objects).WithMany(p => p.Parents)
                .UsingEntity<Dictionary<string, object>>(
                    "AtuserGroup",
                    r => r.HasOne<Atuser>().WithMany()
                        .HasPrincipalKey("ObjectId")
                        .HasForeignKey("ObjectId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("ATUserGroup_ATUser_User"),
                    l => l.HasOne<Atuser>().WithMany()
                        .HasPrincipalKey("ObjectId")
                        .HasForeignKey("ParentId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("ATUserGroup_ATUser_Group"),
                    j =>
                    {
                        j.HasKey("ObjectId", "ParentId");
                        j.ToTable("ATUserGroup");
                    });

            entity.HasMany(d => d.Parents).WithMany(p => p.Objects)
                .UsingEntity<Dictionary<string, object>>(
                    "AtuserGroup",
                    r => r.HasOne<Atuser>().WithMany()
                        .HasPrincipalKey("ObjectId")
                        .HasForeignKey("ParentId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("ATUserGroup_ATUser_Group"),
                    l => l.HasOne<Atuser>().WithMany()
                        .HasPrincipalKey("ObjectId")
                        .HasForeignKey("ObjectId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("ATUserGroup_ATUser_User"),
                    j =>
                    {
                        j.HasKey("ObjectId", "ParentId");
                        j.ToTable("ATUserGroup");
                    });
        });

        modelBuilder.Entity<AtuserProperty>(entity =>
        {
            entity.HasOne(d => d.UserNameNavigation).WithMany(p => p.AtuserProperties)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATUserProperty_ATUser");
        });

        modelBuilder.Entity<AtuserPropertyDefinition>(entity =>
        {
            entity.Property(e => e.PropertyId).ValueGeneratedOnAdd();
        });

        modelBuilder.Entity<AtuserSystemVariable>(entity =>
        {
            entity.HasKey(e => e.Id)
                .HasName("PK_AtUserSystemVariable")
                .IsClustered(false);
        });

        modelBuilder.Entity<AtvariableDefinition>(entity =>
        {
            entity.Property(e => e.VariableId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtvariableInstanceBinaryBlob>(entity =>
        {
            entity.Property(e => e.InstanceId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtvariableInstanceDate>(entity =>
        {
            entity.Property(e => e.InstanceId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtvariableInstanceNumber>(entity =>
        {
            entity.Property(e => e.InstanceId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtvariableInstanceString>(entity =>
        {
            entity.Property(e => e.InstanceId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtvariableInstanceTextBlob>(entity =>
        {
            entity.Property(e => e.InstanceId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtworkItem>(entity =>
        {
            entity.HasKey(e => e.WorkItemId)
                .HasName("PK_WorkItem")
                .IsClustered(false);

            entity.Property(e => e.Created).HasDefaultValueSql("(getdate())");

            entity.HasOne(d => d.CreatorNavigation).WithMany(p => p.AtworkItemCreatorNavigations)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATWorkItem_Creator");

            entity.HasOne(d => d.LockedByNavigation).WithMany(p => p.AtworkItemLockedByNavigations).HasConstraintName("ATWorkItem_LockedByUser");

            entity.HasOne(d => d.Process).WithMany(p => p.AtworkItems)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATWorkItem_Process");
        });

        modelBuilder.Entity<AtworkItemArc>(entity =>
        {
            entity.HasKey(e => e.WorkItemId)
                .HasName("PK_WorkItemArc")
                .IsClustered(false);

            entity.Property(e => e.WorkItemId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtworkItemReference>(entity =>
        {
            entity.HasKey(e => e.WorkItemReferenceId)
                .HasName("PK_WorkItemReference")
                .IsClustered(false);

            entity.HasOne(d => d.AssignedToNavigation).WithMany(p => p.AtworkItemReferenceAssignedToNavigations).HasConstraintName("ATWorkItemReference_AssignTo_ATUser");

            entity.HasOne(d => d.Event).WithMany(p => p.AtworkItemReferenceEvents).HasConstraintName("ATWorkItemReference_ATEventDefinition");

            entity.HasOne(d => d.Queue).WithMany(p => p.AtworkItemReferenceQueues).HasConstraintName("ATWorkItemReference_Queue");

            entity.HasOne(d => d.SourceQueue).WithMany(p => p.AtworkItemReferenceSourceQueues).HasConstraintName("ATWorkItemReference_SourceQueue");

            entity.HasOne(d => d.SourceUserNavigation).WithMany(p => p.AtworkItemReferenceSourceUserNavigations).HasConstraintName("ATWorkItemReference_SourceUser_ATUser");

            entity.HasOne(d => d.SuccessorNavigation).WithMany(p => p.AtworkItemReferenceSuccessorNavigations).HasConstraintName("ATWorkItemReference_ATEventDefinition_Successor");

            entity.HasOne(d => d.WorkItem).WithMany(p => p.AtworkItemReferences)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("ATWorkItemReference_ATWorkItem");
        });

        modelBuilder.Entity<AtworkItemReferenceArc>(entity =>
        {
            entity.HasKey(e => e.WorkItemReferenceId)
                .HasName("PK_WorkItemReferenceArc")
                .IsClustered(false);

            entity.Property(e => e.WorkItemReferenceId).ValueGeneratedNever();
        });

        modelBuilder.Entity<AtxmlHierarchyDefinition>(entity =>
        {
            entity.HasOne(d => d.Hierarch).WithMany(p => p.AtxmlHierarchyDefinitions).HasConstraintName("FK_ATXmlHierarchyDefinition_HierarchId");

            entity.HasOne(d => d.Parent).WithMany(p => p.InverseParent).HasConstraintName("FK_ATXmlHierarchyDefinition_ParentId");
        });

        modelBuilder.Entity<AtxmlTemplateDefinition>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_ATXmlTemplateDef");

            entity.HasOne(d => d.FieldSource).WithMany(p => p.AtxmlTemplateDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATXmlTemplateDef_FieldSourceId");

            entity.HasOne(d => d.Template).WithMany(p => p.AtxmlTemplateDefinitions)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ATXmlTemplateDef_TemplateId");

            entity.HasOne(d => d.XmlParent).WithMany(p => p.AtxmlTemplateDefinitions)
                .OnDelete(DeleteBehavior.SetNull)
                .HasConstraintName("FK_ATXmlTemplateDef_XmlParentId");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
