//---------------------------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated by T4Model template for T4 (https://github.com/linq2db/linq2db).
//    Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//---------------------------------------------------------------------------------------------------

#pragma warning disable 1573, 1591
#nullable enable

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

using LinqToDB;
using LinqToDB.Common;
using LinqToDB.Configuration;
using LinqToDB.Data;
using LinqToDB.Mapping;

namespace Default.Access.OleDb
{
	public partial class TestDataDB : LinqToDB.Data.DataConnection
	{
		public ITable<AllType>             AllTypes             { get { return this.GetTable<AllType>(); } }
		public ITable<Child>               Children             { get { return this.GetTable<Child>(); } }
		public ITable<DataTypeTest>        DataTypeTests        { get { return this.GetTable<DataTypeTest>(); } }
		public ITable<Doctor>              Doctors              { get { return this.GetTable<Doctor>(); } }
		public ITable<Dual>                Duals                { get { return this.GetTable<Dual>(); } }
		public ITable<GrandChild>          GrandChildren        { get { return this.GetTable<GrandChild>(); } }
		public ITable<InheritanceChild>    InheritanceChildren  { get { return this.GetTable<InheritanceChild>(); } }
		public ITable<InheritanceParent>   InheritanceParents   { get { return this.GetTable<InheritanceParent>(); } }
		public ITable<LinqDataType>        LinqDataTypes        { get { return this.GetTable<LinqDataType>(); } }
		public ITable<LinqDataTypesQuery>  LinqDataTypesQueries { get { return this.GetTable<LinqDataTypesQuery>(); } }
		public ITable<LinqDataTypesQuery1> LinqDataTypesQuery1  { get { return this.GetTable<LinqDataTypesQuery1>(); } }
		public ITable<LinqDataTypesQuery2> LinqDataTypesQuery2  { get { return this.GetTable<LinqDataTypesQuery2>(); } }
		public ITable<Parent>              Parents              { get { return this.GetTable<Parent>(); } }
		public ITable<Patient>             Patients             { get { return this.GetTable<Patient>(); } }
		public ITable<PatientSelectAll>    PatientSelectAll     { get { return this.GetTable<PatientSelectAll>(); } }
		public ITable<Person>              People               { get { return this.GetTable<Person>(); } }
		public ITable<PersonSelectAll>     PersonSelectAll      { get { return this.GetTable<PersonSelectAll>(); } }
		public ITable<ScalarDataReader>    ScalarDataReaders    { get { return this.GetTable<ScalarDataReader>(); } }
		public ITable<TestIdentity>        TestIdentities       { get { return this.GetTable<TestIdentity>(); } }
		public ITable<TestMerge1>          TestMerge1           { get { return this.GetTable<TestMerge1>(); } }
		public ITable<TestMerge2>          TestMerge2           { get { return this.GetTable<TestMerge2>(); } }

		public TestDataDB()
		{
			InitDataContext();
			InitMappingSchema();
		}

		public TestDataDB(string configuration)
			: base(configuration)
		{
			InitDataContext();
			InitMappingSchema();
		}

		public TestDataDB(DataOptions options)
			: base(options)
		{
			InitDataContext();
			InitMappingSchema();
		}

		partial void InitDataContext  ();
		partial void InitMappingSchema();
	}

	[Table("AllTypes")]
	public partial class AllType
	{
		[Column(),                           NotNull    ] public int       ID                       { get; set; } // Long
		[Column("bitDataType"),              NotNull    ] public bool      BitDataType              { get; set; } // Bit
		[Column("smallintDataType"),            Nullable] public short?    SmallintDataType         { get; set; } // Short
		[Column("decimalDataType"),             Nullable] public decimal?  DecimalDataType          { get; set; } // Decimal(18, 0)
		[Column("intDataType"),                 Nullable] public int?      IntDataType              { get; set; } // Long
		[Column("tinyintDataType"),             Nullable] public byte?     TinyintDataType          { get; set; } // Byte
		[Column("moneyDataType"),               Nullable] public decimal?  MoneyDataType            { get; set; } // Currency
		[Column("floatDataType"),               Nullable] public double?   FloatDataType            { get; set; } // Double
		[Column("realDataType"),                Nullable] public float?    RealDataType             { get; set; } // Single
		[Column("datetimeDataType"),            Nullable] public DateTime? DatetimeDataType         { get; set; } // DateTime
		[Column("charDataType"),                Nullable] public char?     CharDataType             { get; set; } // CHAR(1)
		[Column("char20DataType"),              Nullable] public string?   Char20DataType           { get; set; } // CHAR(20)
		[Column("varcharDataType"),             Nullable] public string?   VarcharDataType          { get; set; } // VarChar(20)
		[Column("textDataType"),                Nullable] public string?   TextDataType             { get; set; } // LongText
		[Column("ncharDataType"),               Nullable] public string?   NcharDataType            { get; set; } // CHAR(20)
		[Column("nvarcharDataType"),            Nullable] public string?   NvarcharDataType         { get; set; } // VarChar(20)
		[Column("ntextDataType"),               Nullable] public string?   NtextDataType            { get; set; } // LongText
		[Column("binaryDataType"),              Nullable] public byte[]?   BinaryDataType           { get; set; } // VARBINARY(10)
		[Column("varbinaryDataType"),           Nullable] public byte[]?   VarbinaryDataType        { get; set; } // VARBINARY(510)
		[Column("imageDataType"),               Nullable] public byte[]?   ImageDataType            { get; set; } // LongBinary
		[Column("oleObjectDataType"),           Nullable] public byte[]?   OleObjectDataType        { get; set; } // LongBinary
		[Column("uniqueidentifierDataType"),    Nullable] public Guid?     UniqueidentifierDataType { get; set; } // GUID
	}

	[Table("Child")]
	public partial class Child
	{
		[Column, Nullable] public int? ParentID { get; set; } // Long
		[Column, Nullable] public int? ChildID  { get; set; } // Long
	}

	[Table("DataTypeTest")]
	public partial class DataTypeTest
	{
		[Column(),            PrimaryKey,  NotNull] public int       DataTypeID { get; set; } // Long
		[Column("Binary_"),      Nullable         ] public byte[]?   Binary     { get; set; } // LongBinary
		[Column("Boolean_"),     Nullable         ] public int?      Boolean    { get; set; } // Long
		[Column("Byte_"),        Nullable         ] public byte?     Byte       { get; set; } // Byte
		[Column("Bytes_"),       Nullable         ] public byte[]?   Bytes      { get; set; } // LongBinary
		[Column("Char_"),        Nullable         ] public char?     Char       { get; set; } // VarChar(1)
		[Column("DateTime_"),    Nullable         ] public DateTime? DateTime   { get; set; } // DateTime
		[Column("Decimal_"),     Nullable         ] public decimal?  Decimal    { get; set; } // Currency
		[Column("Double_"),      Nullable         ] public double?   Double     { get; set; } // Double
		[Column("Guid_"),        Nullable         ] public Guid?     Guid       { get; set; } // GUID
		[Column("Int16_"),       Nullable         ] public short?    Int16      { get; set; } // Short
		[Column("Int32_"),       Nullable         ] public int?      Int32      { get; set; } // Long
		[Column("Int64_"),       Nullable         ] public int?      Int64      { get; set; } // Long
		[Column("Money_"),       Nullable         ] public decimal?  Money      { get; set; } // Currency
		[Column("SByte_"),       Nullable         ] public byte?     SByte      { get; set; } // Byte
		[Column("Single_"),      Nullable         ] public float?    Single     { get; set; } // Single
		[Column("Stream_"),      Nullable         ] public byte[]?   Stream     { get; set; } // LongBinary
		[Column("String_"),      Nullable         ] public string?   String     { get; set; } // VarChar(50)
		[Column("UInt16_"),      Nullable         ] public short?    UInt16     { get; set; } // Short
		[Column("UInt32_"),      Nullable         ] public int?      UInt32     { get; set; } // Long
		[Column("UInt64_"),      Nullable         ] public int?      UInt64     { get; set; } // Long
		[Column("Xml_"),         Nullable         ] public string?   Xml        { get; set; } // LongText
	}

	[Table("Doctor")]
	public partial class Doctor
	{
		[PrimaryKey, NotNull] public int    PersonID { get; set; } // Long
		[Column,     NotNull] public string Taxonomy { get; set; } = null!; // VarChar(50)

		#region Associations

		/// <summary>
		/// PersonDoctor (Person)
		/// </summary>
		[Association(ThisKey="PersonID", OtherKey="PersonID", CanBeNull=false)]
		public Person Person { get; set; } = null!;

		#endregion
	}

	[Table("Dual")]
	public partial class Dual
	{
		[Column, Nullable] public string? Dummy { get; set; } // VarChar(10)
	}

	[Table("GrandChild")]
	public partial class GrandChild
	{
		[Column, Nullable] public int? ParentID     { get; set; } // Long
		[Column, Nullable] public int? ChildID      { get; set; } // Long
		[Column, Nullable] public int? GrandChildID { get; set; } // Long
	}

	[Table("InheritanceChild")]
	public partial class InheritanceChild
	{
		[PrimaryKey, NotNull    ] public int     InheritanceChildId  { get; set; } // Long
		[Column,     NotNull    ] public int     InheritanceParentId { get; set; } // Long
		[Column,        Nullable] public int?    TypeDiscriminator   { get; set; } // Long
		[Column,        Nullable] public string? Name                { get; set; } // VarChar(50)
	}

	[Table("InheritanceParent")]
	public partial class InheritanceParent
	{
		[PrimaryKey, NotNull    ] public int     InheritanceParentId { get; set; } // Long
		[Column,        Nullable] public int?    TypeDiscriminator   { get; set; } // Long
		[Column,        Nullable] public string? Name                { get; set; } // VarChar(50)
	}

	[Table("LinqDataTypes")]
	public partial class LinqDataType
	{
		[Column,    Nullable] public int?      ID             { get; set; } // Long
		[Column,    Nullable] public decimal?  MoneyValue     { get; set; } // Decimal(10, 4)
		[Column,    Nullable] public DateTime? DateTimeValue  { get; set; } // DateTime
		[Column,    Nullable] public DateTime? DateTimeValue2 { get; set; } // DateTime
		[Column, NotNull    ] public bool      BoolValue      { get; set; } // Bit
		[Column,    Nullable] public Guid?     GuidValue      { get; set; } // GUID
		[Column,    Nullable] public byte[]?   BinaryValue    { get; set; } // LongBinary
		[Column,    Nullable] public short?    SmallIntValue  { get; set; } // Short
		[Column,    Nullable] public int?      IntValue       { get; set; } // Long
		[Column,    Nullable] public int?      BigIntValue    { get; set; } // Long
		[Column,    Nullable] public string?   StringValue    { get; set; } // VarChar(50)
	}

	[Table("LinqDataTypes Query", IsView=true)]
	public partial class LinqDataTypesQuery
	{
		[Column, Nullable] public DateTime? DateTimeValue { get; set; } // DateTime
	}

	[Table("LinqDataTypes Query1", IsView=true)]
	public partial class LinqDataTypesQuery1
	{
		[Column, Nullable] public int? ID { get; set; } // Long
	}

	[Table("LinqDataTypes Query2", IsView=true)]
	public partial class LinqDataTypesQuery2
	{
		[Column, Nullable] public int? ID { get; set; } // Long
	}

	[Table("Parent")]
	public partial class Parent
	{
		[Column, Nullable] public int? ParentID { get; set; } // Long
		[Column, Nullable] public int? Value1   { get; set; } // Long
	}

	[Table("Patient")]
	public partial class Patient
	{
		[PrimaryKey, NotNull] public int    PersonID  { get; set; } // Long
		[Column,     NotNull] public string Diagnosis { get; set; } = null!; // VarChar(255)

		#region Associations

		/// <summary>
		/// PersonPatient (Person)
		/// </summary>
		[Association(ThisKey="PersonID", OtherKey="PersonID", CanBeNull=false)]
		public Person Person { get; set; } = null!;

		#endregion
	}

	[Table("Patient_SelectAll", IsView=true)]
	public partial class PatientSelectAll
	{
		[Column, NotNull    ] public int     PersonID   { get; set; } // Long
		[Column,    Nullable] public string? FirstName  { get; set; } // VarChar(50)
		[Column,    Nullable] public string? LastName   { get; set; } // VarChar(50)
		[Column,    Nullable] public string? MiddleName { get; set; } // VarChar(50)
		[Column,    Nullable] public char?   Gender     { get; set; } // VarChar(1)
		[Column,    Nullable] public string? Diagnosis  { get; set; } // VarChar(255)
	}

	[Table("Person")]
	public partial class Person
	{
		[PrimaryKey, NotNull    ] public int     PersonID   { get; set; } // Long
		[Column,     NotNull    ] public string  FirstName  { get; set; } = null!; // VarChar(50)
		[Column,     NotNull    ] public string  LastName   { get; set; } = null!; // VarChar(50)
		[Column,        Nullable] public string? MiddleName { get; set; } // VarChar(50)
		[Column,     NotNull    ] public char    Gender     { get; set; } // VarChar(1)

		#region Associations

		/// <summary>
		/// PersonDoctor_BackReference (Doctor)
		/// </summary>
		[Association(ThisKey="PersonID", OtherKey="PersonID", CanBeNull=true)]
		public Doctor? PersonDoctor { get; set; }

		/// <summary>
		/// PersonPatient_BackReference (Patient)
		/// </summary>
		[Association(ThisKey="PersonID", OtherKey="PersonID", CanBeNull=true)]
		public Patient? PersonPatient { get; set; }

		#endregion
	}

	[Table("Person_SelectAll", IsView=true)]
	public partial class PersonSelectAll
	{
		[Column, NotNull    ] public int     PersonID   { get; set; } // Long
		[Column,    Nullable] public string? FirstName  { get; set; } // VarChar(50)
		[Column,    Nullable] public string? LastName   { get; set; } // VarChar(50)
		[Column,    Nullable] public string? MiddleName { get; set; } // VarChar(50)
		[Column,    Nullable] public char?   Gender     { get; set; } // VarChar(1)
	}

	[Table("Scalar_DataReader", IsView=true)]
	public partial class ScalarDataReader
	{
		[Column("intField"),    Nullable] public int?    IntField    { get; set; } // Long
		[Column("stringField"), Nullable] public string? StringField { get; set; } // LongText
	}

	[Table("TestIdentity")]
	public partial class TestIdentity
	{
		[PrimaryKey, NotNull] public int ID { get; set; } // Long
	}

	[Table("TestMerge1")]
	public partial class TestMerge1
	{
		[PrimaryKey, NotNull    ] public int       Id              { get; set; } // Long
		[Column,        Nullable] public int?      Field1          { get; set; } // Long
		[Column,        Nullable] public int?      Field2          { get; set; } // Long
		[Column,        Nullable] public int?      Field3          { get; set; } // Long
		[Column,        Nullable] public int?      Field4          { get; set; } // Long
		[Column,        Nullable] public int?      Field5          { get; set; } // Long
		[Column,     NotNull    ] public bool      FieldBoolean    { get; set; } // Bit
		[Column,        Nullable] public string?   FieldString     { get; set; } // VarChar(20)
		[Column,        Nullable] public string?   FieldNString    { get; set; } // VarChar(20)
		[Column,        Nullable] public char?     FieldChar       { get; set; } // CHAR(1)
		[Column,        Nullable] public char?     FieldNChar      { get; set; } // CHAR(1)
		[Column,        Nullable] public float?    FieldFloat      { get; set; } // Single
		[Column,        Nullable] public double?   FieldDouble     { get; set; } // Double
		[Column,        Nullable] public DateTime? FieldDateTime   { get; set; } // DateTime
		[Column,        Nullable] public byte[]?   FieldBinary     { get; set; } // VARBINARY(20)
		[Column,        Nullable] public Guid?     FieldGuid       { get; set; } // GUID
		[Column,        Nullable] public decimal?  FieldDecimal    { get; set; } // Decimal(24, 10)
		[Column,        Nullable] public DateTime? FieldDate       { get; set; } // DateTime
		[Column,        Nullable] public DateTime? FieldTime       { get; set; } // DateTime
		[Column,        Nullable] public string?   FieldEnumString { get; set; } // VarChar(20)
		[Column,        Nullable] public int?      FieldEnumNumber { get; set; } // Long
	}

	[Table("TestMerge2")]
	public partial class TestMerge2
	{
		[PrimaryKey, NotNull    ] public int       Id              { get; set; } // Long
		[Column,        Nullable] public int?      Field1          { get; set; } // Long
		[Column,        Nullable] public int?      Field2          { get; set; } // Long
		[Column,        Nullable] public int?      Field3          { get; set; } // Long
		[Column,        Nullable] public int?      Field4          { get; set; } // Long
		[Column,        Nullable] public int?      Field5          { get; set; } // Long
		[Column,     NotNull    ] public bool      FieldBoolean    { get; set; } // Bit
		[Column,        Nullable] public string?   FieldString     { get; set; } // VarChar(20)
		[Column,        Nullable] public string?   FieldNString    { get; set; } // VarChar(20)
		[Column,        Nullable] public char?     FieldChar       { get; set; } // CHAR(1)
		[Column,        Nullable] public char?     FieldNChar      { get; set; } // CHAR(1)
		[Column,        Nullable] public float?    FieldFloat      { get; set; } // Single
		[Column,        Nullable] public double?   FieldDouble     { get; set; } // Double
		[Column,        Nullable] public DateTime? FieldDateTime   { get; set; } // DateTime
		[Column,        Nullable] public byte[]?   FieldBinary     { get; set; } // VARBINARY(20)
		[Column,        Nullable] public Guid?     FieldGuid       { get; set; } // GUID
		[Column,        Nullable] public decimal?  FieldDecimal    { get; set; } // Decimal(24, 10)
		[Column,        Nullable] public DateTime? FieldDate       { get; set; } // DateTime
		[Column,        Nullable] public DateTime? FieldTime       { get; set; } // DateTime
		[Column,        Nullable] public string?   FieldEnumString { get; set; } // VarChar(20)
		[Column,        Nullable] public int?      FieldEnumNumber { get; set; } // Long
	}

	public static partial class TestDataDBStoredProcedures
	{
		#region AddIssue792Record

		public static int AddIssue792Record(this TestDataDB dataConnection)
		{
			return dataConnection.ExecuteProc("[AddIssue792Record]");
		}

		#endregion

		#region PatientSelectByName

		public static IEnumerable<PatientSelectAll> PatientSelectByName(this TestDataDB dataConnection, string? @firstName, string? @lastName)
		{
			var parameters = new []
			{
				new DataParameter("@firstName", @firstName, LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@lastName",  @lastName,  LinqToDB.DataType.NText)
				{
					Size = 50
				}
			};

			return dataConnection.QueryProc<PatientSelectAll>("[Patient_SelectByName]", parameters);
		}

		#endregion

		#region PersonDelete

		public static int PersonDelete(this TestDataDB dataConnection, int? @PersonID)
		{
			var parameters = new []
			{
				new DataParameter("@PersonID", @PersonID, LinqToDB.DataType.Int32)
			};

			return dataConnection.ExecuteProc("[Person_Delete]", parameters);
		}

		#endregion

		#region PersonInsert

		public static int PersonInsert(this TestDataDB dataConnection, string? @FirstName, string? @MiddleName, string? @LastName, char? @Gender)
		{
			var parameters = new []
			{
				new DataParameter("@FirstName",  @FirstName,  LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@MiddleName", @MiddleName, LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@LastName",   @LastName,   LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@Gender",     @Gender,     LinqToDB.DataType.NText)
				{
					Size = 1
				}
			};

			return dataConnection.ExecuteProc("[Person_Insert]", parameters);
		}

		#endregion

		#region PersonSelectByKey

		public static IEnumerable<Person> PersonSelectByKey(this TestDataDB dataConnection, int? @id)
		{
			var parameters = new []
			{
				new DataParameter("@id", @id, LinqToDB.DataType.Int32)
			};

			return dataConnection.QueryProc<Person>("[Person_SelectByKey]", parameters);
		}

		#endregion

		#region PersonSelectByName

		public static IEnumerable<Person> PersonSelectByName(this TestDataDB dataConnection, string? @firstName, string? @lastName)
		{
			var parameters = new []
			{
				new DataParameter("@firstName", @firstName, LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@lastName",  @lastName,  LinqToDB.DataType.NText)
				{
					Size = 50
				}
			};

			return dataConnection.QueryProc<Person>("[Person_SelectByName]", parameters);
		}

		#endregion

		#region PersonSelectListByName

		public static IEnumerable<Person> PersonSelectListByName(this TestDataDB dataConnection, string? @firstName, string? @lastName)
		{
			var parameters = new []
			{
				new DataParameter("@firstName", @firstName, LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@lastName",  @lastName,  LinqToDB.DataType.NText)
				{
					Size = 50
				}
			};

			return dataConnection.QueryProc<Person>("[Person_SelectListByName]", parameters);
		}

		#endregion

		#region PersonUpdate

		public static int PersonUpdate(this TestDataDB dataConnection, int? @id, int? @PersonID, string? @FirstName, string? @MiddleName, string? @LastName, char? @Gender)
		{
			var parameters = new []
			{
				new DataParameter("@id",         @id,         LinqToDB.DataType.Int32),
				new DataParameter("@PersonID",   @PersonID,   LinqToDB.DataType.Int32),
				new DataParameter("@FirstName",  @FirstName,  LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@MiddleName", @MiddleName, LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@LastName",   @LastName,   LinqToDB.DataType.NText)
				{
					Size = 50
				},
				new DataParameter("@Gender",     @Gender,     LinqToDB.DataType.NText)
				{
					Size = 1
				}
			};

			return dataConnection.ExecuteProc("[Person_Update]", parameters);
		}

		#endregion
	}

	public static partial class TableExtensions
	{
		public static DataTypeTest? Find(this ITable<DataTypeTest> table, int DataTypeID)
		{
			return table.FirstOrDefault(t =>
				t.DataTypeID == DataTypeID);
		}

		public static Doctor? Find(this ITable<Doctor> table, int PersonID)
		{
			return table.FirstOrDefault(t =>
				t.PersonID == PersonID);
		}

		public static InheritanceChild? Find(this ITable<InheritanceChild> table, int InheritanceChildId)
		{
			return table.FirstOrDefault(t =>
				t.InheritanceChildId == InheritanceChildId);
		}

		public static InheritanceParent? Find(this ITable<InheritanceParent> table, int InheritanceParentId)
		{
			return table.FirstOrDefault(t =>
				t.InheritanceParentId == InheritanceParentId);
		}

		public static Patient? Find(this ITable<Patient> table, int PersonID)
		{
			return table.FirstOrDefault(t =>
				t.PersonID == PersonID);
		}

		public static Person? Find(this ITable<Person> table, int PersonID)
		{
			return table.FirstOrDefault(t =>
				t.PersonID == PersonID);
		}

		public static TestIdentity? Find(this ITable<TestIdentity> table, int ID)
		{
			return table.FirstOrDefault(t =>
				t.ID == ID);
		}

		public static TestMerge1? Find(this ITable<TestMerge1> table, int Id)
		{
			return table.FirstOrDefault(t =>
				t.Id == Id);
		}

		public static TestMerge2? Find(this ITable<TestMerge2> table, int Id)
		{
			return table.FirstOrDefault(t =>
				t.Id == Id);
		}
	}
}
