// <auto-generated />
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.ValueGeneration.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage.Json;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using Newtonsoft.Json.Linq;

#pragma warning disable 219, 612, 618
#nullable disable

namespace TestNamespace
{
    [EntityFrameworkInternal]
    public partial class PrincipalBasePrincipalDerivedDependentBasebyteEntityType
    {
        public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null)
        {
            var runtimeEntityType = model.AddEntityType(
                "PrincipalBasePrincipalDerived<DependentBase<byte?>>",
                typeof(Dictionary<string, object>),
                baseEntityType,
                sharedClrType: true,
                indexerPropertyInfo: RuntimeEntityType.FindIndexerProperty(typeof(Dictionary<string, object>)),
                propertyBag: true,
                discriminatorProperty: "$type",
                discriminatorValue: "PrincipalBasePrincipalDerived<DependentBase<byte?>>",
                propertyCount: 8,
                foreignKeyCount: 2,
                keyCount: 1);

            var derivedsId = runtimeEntityType.AddProperty(
                "DerivedsId",
                typeof(long),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                afterSaveBehavior: PropertySaveBehavior.Throw);
            derivedsId.SetGetter(
                long (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("DerivedsId") ? instance["DerivedsId"] : null) == null ? 0L : ((long)((((IDictionary<string, object>)instance).ContainsKey("DerivedsId") ? instance["DerivedsId"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("DerivedsId") ? instance["DerivedsId"] : null) == null);
            derivedsId.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, long value) =>
                {
                    instance["DerivedsId"] = ((object)value);
                    return instance;
                });
            derivedsId.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, long value) =>
                {
                    instance["DerivedsId"] = ((object)value);
                    return instance;
                });
            derivedsId.SetAccessors(
                long (IInternalEntry entry) =>
                {
                    if (entry.FlaggedAsStoreGenerated(0))
                    {
                        return entry.ReadStoreGeneratedValue<long>(0);
                    }
                    else
                    {
                        {
                            if (entry.FlaggedAsTemporary(0) && (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("DerivedsId") ? ((Dictionary<string, object>)(entry.Entity))["DerivedsId"] : null) == null)
                            {
                                return entry.ReadTemporaryValue<long>(0);
                            }
                            else
                            {
                                var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("DerivedsId") ? ((Dictionary<string, object>)(entry.Entity))["DerivedsId"] : null);
                                return (nullableValue == null ? default(long) : ((long)nullableValue));
                            }
                        }
                    }
                },
                long (IInternalEntry entry) =>
                {
                    var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("DerivedsId") ? ((Dictionary<string, object>)(entry.Entity))["DerivedsId"] : null);
                    return (nullableValue == null ? default(long) : ((long)nullableValue));
                },
                long (IInternalEntry entry) => entry.ReadOriginalValue<long>(derivedsId, 0),
                long (IInternalEntry entry) => ((InternalEntityEntry)entry).ReadRelationshipSnapshotValue<long>(derivedsId, 0));
            derivedsId.SetPropertyIndexes(
                index: 0,
                originalValueIndex: 0,
                shadowIndex: -1,
                relationshipIndex: 0,
                storeGenerationIndex: 0);
            derivedsId.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<long>(
                    bool (long v1, long v2) => v1 == v2,
                    int (long v) => ((object)v).GetHashCode(),
                    long (long v) => v),
                keyComparer: new ValueComparer<long>(
                    bool (long v1, long v2) => v1 == v2,
                    int (long v) => ((object)v).GetHashCode(),
                    long (long v) => v),
                providerValueComparer: new ValueComparer<long>(
                    bool (long v1, long v2) => v1 == v2,
                    int (long v) => ((object)v).GetHashCode(),
                    long (long v) => v),
                clrType: typeof(long),
                jsonValueReaderWriter: JsonInt64ReaderWriter.Instance);
            derivedsId.SetCurrentValueComparer(new EntryCurrentValueComparer<long>(derivedsId));

            var derivedsAlternateId = runtimeEntityType.AddProperty(
                "DerivedsAlternateId",
                typeof(Guid),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                afterSaveBehavior: PropertySaveBehavior.Throw);
            derivedsAlternateId.SetGetter(
                Guid (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("DerivedsAlternateId") ? instance["DerivedsAlternateId"] : null) == null ? new Guid("00000000-0000-0000-0000-000000000000") : ((Guid)((((IDictionary<string, object>)instance).ContainsKey("DerivedsAlternateId") ? instance["DerivedsAlternateId"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("DerivedsAlternateId") ? instance["DerivedsAlternateId"] : null) == null);
            derivedsAlternateId.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, Guid value) =>
                {
                    instance["DerivedsAlternateId"] = ((object)value);
                    return instance;
                });
            derivedsAlternateId.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, Guid value) =>
                {
                    instance["DerivedsAlternateId"] = ((object)value);
                    return instance;
                });
            derivedsAlternateId.SetAccessors(
                Guid (IInternalEntry entry) =>
                {
                    if (entry.FlaggedAsStoreGenerated(1))
                    {
                        return entry.ReadStoreGeneratedValue<Guid>(1);
                    }
                    else
                    {
                        {
                            if (entry.FlaggedAsTemporary(1) && (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("DerivedsAlternateId") ? ((Dictionary<string, object>)(entry.Entity))["DerivedsAlternateId"] : null) == null)
                            {
                                return entry.ReadTemporaryValue<Guid>(1);
                            }
                            else
                            {
                                var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("DerivedsAlternateId") ? ((Dictionary<string, object>)(entry.Entity))["DerivedsAlternateId"] : null);
                                return (nullableValue == null ? default(Guid) : ((Guid)nullableValue));
                            }
                        }
                    }
                },
                Guid (IInternalEntry entry) =>
                {
                    var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("DerivedsAlternateId") ? ((Dictionary<string, object>)(entry.Entity))["DerivedsAlternateId"] : null);
                    return (nullableValue == null ? default(Guid) : ((Guid)nullableValue));
                },
                Guid (IInternalEntry entry) => entry.ReadOriginalValue<Guid>(derivedsAlternateId, 1),
                Guid (IInternalEntry entry) => ((InternalEntityEntry)entry).ReadRelationshipSnapshotValue<Guid>(derivedsAlternateId, 1));
            derivedsAlternateId.SetPropertyIndexes(
                index: 1,
                originalValueIndex: 1,
                shadowIndex: -1,
                relationshipIndex: 1,
                storeGenerationIndex: 1);
            derivedsAlternateId.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<Guid>(
                    bool (Guid v1, Guid v2) => v1 == v2,
                    int (Guid v) => ((object)v).GetHashCode(),
                    Guid (Guid v) => v),
                keyComparer: new ValueComparer<Guid>(
                    bool (Guid v1, Guid v2) => v1 == v2,
                    int (Guid v) => ((object)v).GetHashCode(),
                    Guid (Guid v) => v),
                providerValueComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                converter: new ValueConverter<Guid, string>(
                    string (Guid v) => v.ToString("D"),
                    Guid (string v) => new Guid(v)),
                jsonValueReaderWriter: new JsonConvertedValueReaderWriter<Guid, string>(
                    JsonStringReaderWriter.Instance,
                    new ValueConverter<Guid, string>(
                        string (Guid v) => v.ToString("D"),
                        Guid (string v) => new Guid(v))));
            derivedsAlternateId.SetCurrentValueComparer(new EntryCurrentValueComparer<Guid>(derivedsAlternateId));

            var principalsId = runtimeEntityType.AddProperty(
                "PrincipalsId",
                typeof(long),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                afterSaveBehavior: PropertySaveBehavior.Throw);
            principalsId.SetGetter(
                long (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("PrincipalsId") ? instance["PrincipalsId"] : null) == null ? 0L : ((long)((((IDictionary<string, object>)instance).ContainsKey("PrincipalsId") ? instance["PrincipalsId"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("PrincipalsId") ? instance["PrincipalsId"] : null) == null);
            principalsId.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, long value) =>
                {
                    instance["PrincipalsId"] = ((object)value);
                    return instance;
                });
            principalsId.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, long value) =>
                {
                    instance["PrincipalsId"] = ((object)value);
                    return instance;
                });
            principalsId.SetAccessors(
                long (IInternalEntry entry) =>
                {
                    if (entry.FlaggedAsStoreGenerated(2))
                    {
                        return entry.ReadStoreGeneratedValue<long>(2);
                    }
                    else
                    {
                        {
                            if (entry.FlaggedAsTemporary(2) && (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("PrincipalsId") ? ((Dictionary<string, object>)(entry.Entity))["PrincipalsId"] : null) == null)
                            {
                                return entry.ReadTemporaryValue<long>(2);
                            }
                            else
                            {
                                var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("PrincipalsId") ? ((Dictionary<string, object>)(entry.Entity))["PrincipalsId"] : null);
                                return (nullableValue == null ? default(long) : ((long)nullableValue));
                            }
                        }
                    }
                },
                long (IInternalEntry entry) =>
                {
                    var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("PrincipalsId") ? ((Dictionary<string, object>)(entry.Entity))["PrincipalsId"] : null);
                    return (nullableValue == null ? default(long) : ((long)nullableValue));
                },
                long (IInternalEntry entry) => entry.ReadOriginalValue<long>(principalsId, 2),
                long (IInternalEntry entry) => ((InternalEntityEntry)entry).ReadRelationshipSnapshotValue<long>(principalsId, 2));
            principalsId.SetPropertyIndexes(
                index: 2,
                originalValueIndex: 2,
                shadowIndex: -1,
                relationshipIndex: 2,
                storeGenerationIndex: 2);
            principalsId.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<long>(
                    bool (long v1, long v2) => v1 == v2,
                    int (long v) => ((object)v).GetHashCode(),
                    long (long v) => v),
                keyComparer: new ValueComparer<long>(
                    bool (long v1, long v2) => v1 == v2,
                    int (long v) => ((object)v).GetHashCode(),
                    long (long v) => v),
                providerValueComparer: new ValueComparer<long>(
                    bool (long v1, long v2) => v1 == v2,
                    int (long v) => ((object)v).GetHashCode(),
                    long (long v) => v),
                clrType: typeof(long),
                jsonValueReaderWriter: JsonInt64ReaderWriter.Instance);
            principalsId.SetCurrentValueComparer(new EntryCurrentValueComparer<long>(principalsId));

            var principalsAlternateId = runtimeEntityType.AddProperty(
                "PrincipalsAlternateId",
                typeof(Guid),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                afterSaveBehavior: PropertySaveBehavior.Throw);
            principalsAlternateId.SetGetter(
                Guid (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("PrincipalsAlternateId") ? instance["PrincipalsAlternateId"] : null) == null ? new Guid("00000000-0000-0000-0000-000000000000") : ((Guid)((((IDictionary<string, object>)instance).ContainsKey("PrincipalsAlternateId") ? instance["PrincipalsAlternateId"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("PrincipalsAlternateId") ? instance["PrincipalsAlternateId"] : null) == null);
            principalsAlternateId.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, Guid value) =>
                {
                    instance["PrincipalsAlternateId"] = ((object)value);
                    return instance;
                });
            principalsAlternateId.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, Guid value) =>
                {
                    instance["PrincipalsAlternateId"] = ((object)value);
                    return instance;
                });
            principalsAlternateId.SetAccessors(
                Guid (IInternalEntry entry) =>
                {
                    if (entry.FlaggedAsStoreGenerated(3))
                    {
                        return entry.ReadStoreGeneratedValue<Guid>(3);
                    }
                    else
                    {
                        {
                            if (entry.FlaggedAsTemporary(3) && (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("PrincipalsAlternateId") ? ((Dictionary<string, object>)(entry.Entity))["PrincipalsAlternateId"] : null) == null)
                            {
                                return entry.ReadTemporaryValue<Guid>(3);
                            }
                            else
                            {
                                var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("PrincipalsAlternateId") ? ((Dictionary<string, object>)(entry.Entity))["PrincipalsAlternateId"] : null);
                                return (nullableValue == null ? default(Guid) : ((Guid)nullableValue));
                            }
                        }
                    }
                },
                Guid (IInternalEntry entry) =>
                {
                    var nullableValue = (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("PrincipalsAlternateId") ? ((Dictionary<string, object>)(entry.Entity))["PrincipalsAlternateId"] : null);
                    return (nullableValue == null ? default(Guid) : ((Guid)nullableValue));
                },
                Guid (IInternalEntry entry) => entry.ReadOriginalValue<Guid>(principalsAlternateId, 3),
                Guid (IInternalEntry entry) => ((InternalEntityEntry)entry).ReadRelationshipSnapshotValue<Guid>(principalsAlternateId, 3));
            principalsAlternateId.SetPropertyIndexes(
                index: 3,
                originalValueIndex: 3,
                shadowIndex: -1,
                relationshipIndex: 3,
                storeGenerationIndex: 3);
            principalsAlternateId.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<Guid>(
                    bool (Guid v1, Guid v2) => v1 == v2,
                    int (Guid v) => ((object)v).GetHashCode(),
                    Guid (Guid v) => v),
                keyComparer: new ValueComparer<Guid>(
                    bool (Guid v1, Guid v2) => v1 == v2,
                    int (Guid v) => ((object)v).GetHashCode(),
                    Guid (Guid v) => v),
                providerValueComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                converter: new ValueConverter<Guid, string>(
                    string (Guid v) => v.ToString("D"),
                    Guid (string v) => new Guid(v)),
                jsonValueReaderWriter: new JsonConvertedValueReaderWriter<Guid, string>(
                    JsonStringReaderWriter.Instance,
                    new ValueConverter<Guid, string>(
                        string (Guid v) => v.ToString("D"),
                        Guid (string v) => new Guid(v))));
            principalsAlternateId.SetCurrentValueComparer(new EntryCurrentValueComparer<Guid>(principalsAlternateId));

            var type = runtimeEntityType.AddProperty(
                "$type",
                typeof(string),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                afterSaveBehavior: PropertySaveBehavior.Throw,
                valueGeneratorFactory: new DiscriminatorValueGeneratorFactory().Create);
            type.SetGetter(
                string (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("$type") ? instance["$type"] : null) == null ? null : ((string)((((IDictionary<string, object>)instance).ContainsKey("$type") ? instance["$type"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("$type") ? instance["$type"] : null) == null);
            type.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, string value) =>
                {
                    instance["$type"] = ((object)value);
                    return instance;
                });
            type.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, string value) =>
                {
                    instance["$type"] = ((object)value);
                    return instance;
                });
            type.SetAccessors(
                string (IInternalEntry entry) => ((string)((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("$type") ? ((Dictionary<string, object>)(entry.Entity))["$type"] : null))),
                string (IInternalEntry entry) => ((string)((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("$type") ? ((Dictionary<string, object>)(entry.Entity))["$type"] : null))),
                string (IInternalEntry entry) => entry.ReadOriginalValue<string>(type, 4),
                string (IInternalEntry entry) => entry.GetCurrentValue<string>(type));
            type.SetPropertyIndexes(
                index: 4,
                originalValueIndex: 4,
                shadowIndex: -1,
                relationshipIndex: -1,
                storeGenerationIndex: -1);
            type.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                keyComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                providerValueComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                clrType: typeof(string),
                jsonValueReaderWriter: JsonStringReaderWriter.Instance);

            var __id = runtimeEntityType.AddProperty(
                "__id",
                typeof(string),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                afterSaveBehavior: PropertySaveBehavior.Throw,
                valueGeneratorFactory: new IdValueGeneratorFactory().Create);
            __id.SetGetter(
                string (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("__id") ? instance["__id"] : null) == null ? null : ((string)((((IDictionary<string, object>)instance).ContainsKey("__id") ? instance["__id"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("__id") ? instance["__id"] : null) == null);
            __id.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, string value) =>
                {
                    instance["__id"] = ((object)value);
                    return instance;
                });
            __id.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, string value) =>
                {
                    instance["__id"] = ((object)value);
                    return instance;
                });
            __id.SetAccessors(
                string (IInternalEntry entry) => ((string)((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("__id") ? ((Dictionary<string, object>)(entry.Entity))["__id"] : null))),
                string (IInternalEntry entry) => ((string)((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("__id") ? ((Dictionary<string, object>)(entry.Entity))["__id"] : null))),
                string (IInternalEntry entry) => entry.ReadOriginalValue<string>(__id, 5),
                string (IInternalEntry entry) => entry.GetCurrentValue<string>(__id));
            __id.SetPropertyIndexes(
                index: 5,
                originalValueIndex: 5,
                shadowIndex: -1,
                relationshipIndex: -1,
                storeGenerationIndex: -1);
            __id.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                keyComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                providerValueComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                clrType: typeof(string),
                jsonValueReaderWriter: JsonStringReaderWriter.Instance);
            __id.AddAnnotation("Cosmos:PropertyName", "id");

            var __jObject = runtimeEntityType.AddProperty(
                "__jObject",
                typeof(JObject),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                nullable: true,
                valueGenerated: ValueGenerated.OnAddOrUpdate,
                beforeSaveBehavior: PropertySaveBehavior.Ignore,
                afterSaveBehavior: PropertySaveBehavior.Ignore);
            __jObject.SetGetter(
                JObject (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("__jObject") ? instance["__jObject"] : null) == null ? null : ((JObject)((((IDictionary<string, object>)instance).ContainsKey("__jObject") ? instance["__jObject"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("__jObject") ? instance["__jObject"] : null) == null);
            __jObject.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, JObject value) =>
                {
                    instance["__jObject"] = ((object)value);
                    return instance;
                });
            __jObject.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, JObject value) =>
                {
                    instance["__jObject"] = ((object)value);
                    return instance;
                });
            __jObject.SetAccessors(
                JObject (IInternalEntry entry) => (entry.FlaggedAsStoreGenerated(6) ? entry.ReadStoreGeneratedValue<JObject>(4) : (entry.FlaggedAsTemporary(6) && (((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("__jObject") ? ((Dictionary<string, object>)(entry.Entity))["__jObject"] : null) == null ? entry.ReadTemporaryValue<JObject>(4) : ((JObject)((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("__jObject") ? ((Dictionary<string, object>)(entry.Entity))["__jObject"] : null))))),
                JObject (IInternalEntry entry) => ((JObject)((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("__jObject") ? ((Dictionary<string, object>)(entry.Entity))["__jObject"] : null))),
                JObject (IInternalEntry entry) => entry.ReadOriginalValue<JObject>(__jObject, 6),
                JObject (IInternalEntry entry) => entry.GetCurrentValue<JObject>(__jObject));
            __jObject.SetPropertyIndexes(
                index: 6,
                originalValueIndex: 6,
                shadowIndex: -1,
                relationshipIndex: -1,
                storeGenerationIndex: 4);
            __jObject.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<JObject>(
                    bool (JObject v1, JObject v2) => object.Equals(v1, v2),
                    int (JObject v) => ((object)v).GetHashCode(),
                    JObject (JObject v) => v),
                keyComparer: new ValueComparer<JObject>(
                    bool (JObject v1, JObject v2) => object.Equals(v1, v2),
                    int (JObject v) => ((object)v).GetHashCode(),
                    JObject (JObject v) => v),
                providerValueComparer: new ValueComparer<JObject>(
                    bool (JObject v1, JObject v2) => object.Equals(v1, v2),
                    int (JObject v) => ((object)v).GetHashCode(),
                    JObject (JObject v) => v),
                clrType: typeof(JObject));
            __jObject.AddAnnotation("Cosmos:PropertyName", "");

            var rowid = runtimeEntityType.AddProperty(
                "rowid",
                typeof(byte[]),
                propertyInfo: runtimeEntityType.FindIndexerPropertyInfo(),
                nullable: true);
            rowid.SetGetter(
                byte[] (Dictionary<string, object> instance) => ((((IDictionary<string, object>)instance).ContainsKey("rowid") ? instance["rowid"] : null) == null ? null : ((byte[])((((IDictionary<string, object>)instance).ContainsKey("rowid") ? instance["rowid"] : null)))),
                bool (Dictionary<string, object> instance) => (((IDictionary<string, object>)instance).ContainsKey("rowid") ? instance["rowid"] : null) == null);
            rowid.SetSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, byte[] value) =>
                {
                    instance["rowid"] = ((object)value);
                    return instance;
                });
            rowid.SetMaterializationSetter(
                Dictionary<string, object> (Dictionary<string, object> instance, byte[] value) =>
                {
                    instance["rowid"] = ((object)value);
                    return instance;
                });
            rowid.SetAccessors(
                byte[] (IInternalEntry entry) => ((byte[])((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("rowid") ? ((Dictionary<string, object>)(entry.Entity))["rowid"] : null))),
                byte[] (IInternalEntry entry) => ((byte[])((((IDictionary<string, object>)((Dictionary<string, object>)(entry.Entity))).ContainsKey("rowid") ? ((Dictionary<string, object>)(entry.Entity))["rowid"] : null))),
                byte[] (IInternalEntry entry) => entry.ReadOriginalValue<byte[]>(rowid, 7),
                byte[] (IInternalEntry entry) => entry.GetCurrentValue<byte[]>(rowid));
            rowid.SetPropertyIndexes(
                index: 7,
                originalValueIndex: 7,
                shadowIndex: -1,
                relationshipIndex: -1,
                storeGenerationIndex: -1);
            rowid.TypeMapping = CosmosTypeMapping.Default.Clone(
                comparer: new ValueComparer<byte[]>(
                    bool (byte[] v1, byte[] v2) => StructuralComparisons.StructuralEqualityComparer.Equals(((object)v1), ((object)v2)),
                    int (byte[] v) => ((object)v).GetHashCode(),
                    byte[] (byte[] v) => v),
                keyComparer: new ValueComparer<byte[]>(
                    bool (byte[] v1, byte[] v2) => StructuralComparisons.StructuralEqualityComparer.Equals(((object)v1), ((object)v2)),
                    int (byte[] v) => StructuralComparisons.StructuralEqualityComparer.GetHashCode(((object)v)),
                    byte[] (byte[] source) => source.ToArray()),
                providerValueComparer: new ValueComparer<string>(
                    bool (string v1, string v2) => v1 == v2,
                    int (string v) => ((object)v).GetHashCode(),
                    string (string v) => v),
                converter: new ValueConverter<byte[], string>(
                    string (byte[] v) => Convert.ToBase64String(v),
                    byte[] (string v) => Convert.FromBase64String(v)),
                jsonValueReaderWriter: new JsonConvertedValueReaderWriter<byte[], string>(
                    JsonStringReaderWriter.Instance,
                    new ValueConverter<byte[], string>(
                        string (byte[] v) => Convert.ToBase64String(v),
                        byte[] (string v) => Convert.FromBase64String(v))));

            var key = runtimeEntityType.AddKey(
                new[] { derivedsId, derivedsAlternateId, principalsId, principalsAlternateId });
            runtimeEntityType.SetPrimaryKey(key);

            return runtimeEntityType;
        }

        public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType)
        {
            var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("DerivedsId"), declaringEntityType.FindProperty("DerivedsAlternateId") },
                principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id"), principalEntityType.FindProperty("AlternateId") }),
                principalEntityType,
                deleteBehavior: DeleteBehavior.Cascade,
                required: true);

            return runtimeForeignKey;
        }

        public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType)
        {
            var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("PrincipalsId"), declaringEntityType.FindProperty("PrincipalsAlternateId") },
                principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id"), principalEntityType.FindProperty("AlternateId") }),
                principalEntityType,
                deleteBehavior: DeleteBehavior.Cascade,
                required: true);

            return runtimeForeignKey;
        }

        public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
        {
            var derivedsId = runtimeEntityType.FindProperty("DerivedsId");
            var derivedsAlternateId = runtimeEntityType.FindProperty("DerivedsAlternateId");
            var principalsId = runtimeEntityType.FindProperty("PrincipalsId");
            var principalsAlternateId = runtimeEntityType.FindProperty("PrincipalsAlternateId");
            var type = runtimeEntityType.FindProperty("$type");
            var __id = runtimeEntityType.FindProperty("__id");
            var __jObject = runtimeEntityType.FindProperty("__jObject");
            var rowid = runtimeEntityType.FindProperty("rowid");
            var key = runtimeEntityType.FindKey(new[] { derivedsId, derivedsAlternateId, principalsId, principalsAlternateId });
            key.SetPrincipalKeyValueFactory(KeyValueFactoryFactory.CreateCompositeFactory(key));
            key.SetIdentityMapFactory(IdentityMapFactoryFactory.CreateFactory<IReadOnlyList<object>>(key));
            runtimeEntityType.SetOriginalValuesFactory(
                ISnapshot (IInternalEntry source) =>
                {
                    var structuralType5 = ((Dictionary<string, object>)(source.Entity));
                    return ((ISnapshot)(new Snapshot<long, Guid, long, Guid, string, string, JObject, byte[]>(((ValueComparer<long>)(((IProperty)derivedsId).GetValueComparer())).Snapshot(source.GetCurrentValue<long>(derivedsId)), ((ValueComparer<Guid>)(((IProperty)derivedsAlternateId).GetValueComparer())).Snapshot(source.GetCurrentValue<Guid>(derivedsAlternateId)), ((ValueComparer<long>)(((IProperty)principalsId).GetValueComparer())).Snapshot(source.GetCurrentValue<long>(principalsId)), ((ValueComparer<Guid>)(((IProperty)principalsAlternateId).GetValueComparer())).Snapshot(source.GetCurrentValue<Guid>(principalsAlternateId)), (source.GetCurrentValue<string>(type) == null ? null : ((ValueComparer<string>)(((IProperty)type).GetValueComparer())).Snapshot(source.GetCurrentValue<string>(type))), (source.GetCurrentValue<string>(__id) == null ? null : ((ValueComparer<string>)(((IProperty)__id).GetValueComparer())).Snapshot(source.GetCurrentValue<string>(__id))), (source.GetCurrentValue<JObject>(__jObject) == null ? null : ((ValueComparer<JObject>)(((IProperty)__jObject).GetValueComparer())).Snapshot(source.GetCurrentValue<JObject>(__jObject))), (source.GetCurrentValue<byte[]>(rowid) == null ? null : ((ValueComparer<byte[]>)(((IProperty)rowid).GetValueComparer())).Snapshot(source.GetCurrentValue<byte[]>(rowid))))));
                });
            runtimeEntityType.SetStoreGeneratedValuesFactory(
                ISnapshot () => ((ISnapshot)(new Snapshot<long, Guid, long, Guid, JObject>(((ValueComparer<long>)(((IProperty)derivedsId).GetValueComparer())).Snapshot(default(long)), ((ValueComparer<Guid>)(((IProperty)derivedsAlternateId).GetValueComparer())).Snapshot(default(Guid)), ((ValueComparer<long>)(((IProperty)principalsId).GetValueComparer())).Snapshot(default(long)), ((ValueComparer<Guid>)(((IProperty)principalsAlternateId).GetValueComparer())).Snapshot(default(Guid)), (default(JObject) == null ? null : ((ValueComparer<JObject>)(((IProperty)__jObject).GetValueComparer())).Snapshot(default(JObject)))))));
            runtimeEntityType.SetTemporaryValuesFactory(
                ISnapshot (IInternalEntry source) => ((ISnapshot)(new Snapshot<long, Guid, long, Guid, JObject>(default(long), default(Guid), default(long), default(Guid), default(JObject)))));
            runtimeEntityType.SetShadowValuesFactory(
                ISnapshot (IDictionary<string, object> source) => Snapshot.Empty);
            runtimeEntityType.SetEmptyShadowValuesFactory(
                ISnapshot () => Snapshot.Empty);
            runtimeEntityType.SetRelationshipSnapshotFactory(
                ISnapshot (IInternalEntry source) =>
                {
                    var structuralType5 = ((Dictionary<string, object>)(source.Entity));
                    return ((ISnapshot)(new Snapshot<long, Guid, long, Guid>(((ValueComparer<long>)(((IProperty)derivedsId).GetKeyValueComparer())).Snapshot(source.GetCurrentValue<long>(derivedsId)), ((ValueComparer<Guid>)(((IProperty)derivedsAlternateId).GetKeyValueComparer())).Snapshot(source.GetCurrentValue<Guid>(derivedsAlternateId)), ((ValueComparer<long>)(((IProperty)principalsId).GetKeyValueComparer())).Snapshot(source.GetCurrentValue<long>(principalsId)), ((ValueComparer<Guid>)(((IProperty)principalsAlternateId).GetKeyValueComparer())).Snapshot(source.GetCurrentValue<Guid>(principalsAlternateId)))));
                });
            runtimeEntityType.SetCounts(new PropertyCounts(
                propertyCount: 8,
                navigationCount: 0,
                complexPropertyCount: 0,
                complexCollectionCount: 0,
                originalValueCount: 8,
                shadowCount: 0,
                relationshipCount: 4,
                storeGeneratedCount: 5));

            Customize(runtimeEntityType);
        }

        static partial void Customize(RuntimeEntityType runtimeEntityType);
    }
}
