//---------------------------------------------------------------------------------------------------
// <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 System.Reflection;

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

using Microsoft.SqlServer.Types;

namespace TestAzureSQL
{
	public partial class TestDataDB : LinqToDB.Data.DataConnection
	{
		public ITable<AllType>                      AllTypes                  { get { return this.GetTable<AllType>(); } }
		public ITable<AllTypes2>                    AllTypes2                 { get { return this.GetTable<AllTypes2>(); } }
		public ITable<Child>                        Children                  { get { return this.GetTable<Child>(); } }
		public ITable<CollatedTable>                CollatedTables            { get { return this.GetTable<CollatedTable>(); } }
		public ITable<CreateIfNotExistsTable>       CreateIfNotExistsTables   { get { return this.GetTable<CreateIfNotExistsTable>(); } }
		public ITable<sys_DatabaseFirewallRule>     DatabaseFirewallRules     { get { return this.GetTable<sys_DatabaseFirewallRule>(); } }
		public ITable<DataType>                     DataTypes                 { get { return this.GetTable<DataType>(); } }
		public ITable<DecimalOverflow>              DecimalOverflows          { get { return this.GetTable<DecimalOverflow>(); } }
		public ITable<Doctor>                       Doctors                   { get { return this.GetTable<Doctor>(); } }
		public ITable<GrandChild>                   GrandChildren             { get { return this.GetTable<GrandChild>(); } }
		public ITable<GuidID>                       GuidIds                   { get { return this.GetTable<GuidID>(); } }
		public ITable<GuidID2>                      GuidID2                   { get { return this.GetTable<GuidID2>(); } }
		public ITable<IndexTable>                   IndexTables               { get { return this.GetTable<IndexTable>(); } }
		public ITable<IndexTable2>                  IndexTable2               { get { return this.GetTable<IndexTable2>(); } }
		public ITable<InheritanceChild>             InheritanceChildren       { get { return this.GetTable<InheritanceChild>(); } }
		public ITable<InheritanceParent>            InheritanceParents        { get { return this.GetTable<InheritanceParent>(); } }
		public ITable<sys_Ipv6DatabaseFirewallRule> Ipv6DatabaseFirewallRules { get { return this.GetTable<sys_Ipv6DatabaseFirewallRule>(); } }
		public ITable<Issue1115>                    Issue1115                 { get { return this.GetTable<Issue1115>(); } }
		public ITable<Issue1144>                    Issue1144                 { get { return this.GetTable<Issue1144>(); } }
		public ITable<LinqDataType>                 LinqDataTypes             { get { return this.GetTable<LinqDataType>(); } }
		public ITable<Member>                       Members                   { get { return this.GetTable<Member>(); } }
		public ITable<NameTest>                     NameTests                 { get { return this.GetTable<NameTest>(); } }
		public ITable<Parent>                       Parents                   { get { return this.GetTable<Parent>(); } }
		public ITable<ParentChildView>              ParentChildViews          { get { return this.GetTable<ParentChildView>(); } }
		public ITable<ParentView>                   ParentViews               { get { return this.GetTable<ParentView>(); } }
		public ITable<Patient>                      Patients                  { get { return this.GetTable<Patient>(); } }
		public ITable<Person>                       People                    { get { return this.GetTable<Person>(); } }
		public ITable<Provider>                     Providers                 { get { return this.GetTable<Provider>(); } }
		public ITable<SameTableName>                SameTableNames            { get { return this.GetTable<SameTableName>(); } }
		public ITable<TestSchema_SameTableName>     SameTableNames0           { get { return this.GetTable<TestSchema_SameTableName>(); } }
		public ITable<SqlType>                      SqlTypes                  { get { return this.GetTable<SqlType>(); } }
		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 ITable<TestMergeIdentity>            TestMergeIdentities       { get { return this.GetTable<TestMergeIdentity>(); } }
		public ITable<TestSchema_TestSchemaA>       TestSchemaA               { get { return this.GetTable<TestSchema_TestSchemaA>(); } }
		public ITable<TestSchema_TestSchemaB>       TestSchemaB               { get { return this.GetTable<TestSchema_TestSchemaB>(); } }
		public ITable<TestSchemaSameTableName>      TestSchemaSameTableNames  { get { return this.GetTable<TestSchemaSameTableName>(); } }
		public ITable<TestSchemaX>                  TestSchemaX               { get { return this.GetTable<TestSchemaX>(); } }
		public ITable<TestSchemaY>                  TestSchemaY               { get { return this.GetTable<TestSchemaY>(); } }

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

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

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

		#region Table Functions

		#region GetParentByID

		/// <summary>
		/// This is &lt;test&gt; table function!
		/// </summary>
		/// <param name="id">
		/// This is &lt;test&gt; table function parameter!
		/// </param>
		[Sql.TableFunction(Schema="dbo", Name="GetParentByID")]
		public ITable<Parent> GetParentByID(int? @id)
		{
			return this.GetTable<Parent>(this, (MethodInfo)MethodBase.GetCurrentMethod()!,
				@id);
		}

		#endregion

		#region Issue1921

		[Sql.TableFunction(Schema="dbo", Name="Issue1921")]
		public ITable<Issue1921Result> Issue1921()
		{
			return this.GetTable<Issue1921Result>(this, (MethodInfo)MethodBase.GetCurrentMethod()!);
		}

		public partial class Issue1921Result
		{
			[Column("name") ] public string Name  { get; set; } = null!;
			[Column("objid")] public int?   Objid { get; set; }
		}

		#endregion

		#endregion
	}

	[Table(Schema="dbo", Name="AllTypes")]
	public partial class AllType
	{
		[Column(),                                                                 PrimaryKey, Identity] public int             ID                       { get; set; } // int
		[Column("bigintDataType"),                                                 Nullable            ] public long?           BigintDataType           { get; set; } // bigint
		[Column("numericDataType"),                                                Nullable            ] public decimal?        NumericDataType          { get; set; } // numeric(18, 1)
		[Column("bitDataType"),                                                    Nullable            ] public bool?           BitDataType              { get; set; } // bit
		[Column("smallintDataType"),                                               Nullable            ] public short?          SmallintDataType         { get; set; } // smallint
		[Column("decimalDataType"),                                                Nullable            ] public decimal?        DecimalDataType          { get; set; } // decimal(18, 1)
		[Column("smallmoneyDataType"),                                             Nullable            ] public decimal?        SmallmoneyDataType       { get; set; } // smallmoney
		[Column("intDataType"),                                                    Nullable            ] public int?            IntDataType              { get; set; } // int
		[Column("tinyintDataType"),                                                Nullable            ] public byte?           TinyintDataType          { get; set; } // tinyint
		[Column("moneyDataType"),                                                  Nullable            ] public decimal?        MoneyDataType            { get; set; } // money
		[Column("floatDataType"),                                                  Nullable            ] public double?         FloatDataType            { get; set; } // float
		[Column("realDataType"),                                                   Nullable            ] public float?          RealDataType             { get; set; } // real
		[Column("datetimeDataType"),                                               Nullable            ] public DateTime?       DatetimeDataType         { get; set; } // datetime
		[Column("smalldatetimeDataType"),                                          Nullable            ] public DateTime?       SmalldatetimeDataType    { get; set; } // smalldatetime
		[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; } // text
		[Column("ncharDataType"),                                                  Nullable            ] public string?         NcharDataType            { get; set; } // nchar(20)
		[Column("nvarcharDataType"),                                               Nullable            ] public string?         NvarcharDataType         { get; set; } // nvarchar(20)
		[Column("ntextDataType"),                                                  Nullable            ] public string?         NtextDataType            { get; set; } // ntext
		[Column("binaryDataType"),                                                 Nullable            ] public byte[]?         BinaryDataType           { get; set; } // binary(1)
		[Column("varbinaryDataType"),                                              Nullable            ] public byte[]?         VarbinaryDataType        { get; set; } // varbinary(1)
		[Column("imageDataType"),                                                  Nullable            ] public byte[]?         ImageDataType            { get; set; } // image
		[Column("timestampDataType",        SkipOnInsert=true, SkipOnUpdate=true), Nullable            ] public byte[]?         TimestampDataType        { get; set; } // timestamp
		[Column("uniqueidentifierDataType"),                                       Nullable            ] public Guid?           UniqueidentifierDataType { get; set; } // uniqueidentifier
		[Column("sql_variantDataType"),                                            Nullable            ] public object?         SqlVariantDataType       { get; set; } // sql_variant
		[Column("nvarchar_max_DataType"),                                          Nullable            ] public string?         NvarcharMaxDataType      { get; set; } // nvarchar(max)
		[Column("varchar_max_DataType"),                                           Nullable            ] public string?         VarcharMaxDataType       { get; set; } // varchar(max)
		[Column("varbinary_max_DataType"),                                         Nullable            ] public byte[]?         VarbinaryMaxDataType     { get; set; } // varbinary(max)
		[Column("xmlDataType"),                                                    Nullable            ] public string?         XmlDataType              { get; set; } // xml
		[Column("datetime2DataType"),                                              Nullable            ] public DateTime?       Datetime2DataType        { get; set; } // datetime2(7)
		[Column("datetimeoffsetDataType"),                                         Nullable            ] public DateTimeOffset? DatetimeoffsetDataType   { get; set; } // datetimeoffset(7)
		[Column("datetimeoffset0DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset0DataType  { get; set; } // datetimeoffset(0)
		[Column("datetimeoffset1DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset1DataType  { get; set; } // datetimeoffset(1)
		[Column("datetimeoffset2DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset2DataType  { get; set; } // datetimeoffset(2)
		[Column("datetimeoffset3DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset3DataType  { get; set; } // datetimeoffset(3)
		[Column("datetimeoffset4DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset4DataType  { get; set; } // datetimeoffset(4)
		[Column("datetimeoffset5DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset5DataType  { get; set; } // datetimeoffset(5)
		[Column("datetimeoffset6DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset6DataType  { get; set; } // datetimeoffset(6)
		[Column("datetimeoffset7DataType"),                                        Nullable            ] public DateTimeOffset? Datetimeoffset7DataType  { get; set; } // datetimeoffset(7)
		[Column("dateDataType"),                                                   Nullable            ] public DateTime?       DateDataType             { get; set; } // date
		[Column("timeDataType"),                                                   Nullable            ] public TimeSpan?       TimeDataType             { get; set; } // time(7)
	}

	[Table(Schema="dbo", Name="AllTypes2")]
	public partial class AllTypes2
	{
		[Column(),                         PrimaryKey, Identity] public int             ID                     { get; set; } // int
		[Column("dateDataType"),           Nullable            ] public DateTime?       DateDataType           { get; set; } // date
		[Column("datetimeoffsetDataType"), Nullable            ] public DateTimeOffset? DatetimeoffsetDataType { get; set; } // datetimeoffset(7)
		[Column("datetime2DataType"),      Nullable            ] public DateTime?       Datetime2DataType      { get; set; } // datetime2(7)
		[Column("timeDataType"),           Nullable            ] public TimeSpan?       TimeDataType           { get; set; } // time(7)
		[Column("hierarchyidDataType"),    Nullable            ] public SqlHierarchyId? HierarchyidDataType    { get; set; } // hierarchyid
		[Column("geographyDataType"),      Nullable            ] public SqlGeography?   GeographyDataType      { get; set; } // geography
		[Column("geometryDataType"),       Nullable            ] public SqlGeometry?    GeometryDataType       { get; set; } // geometry
	}

	[Table(Schema="dbo", Name="Child")]
	public partial class Child
	{
		[Column(),      Nullable            ] public int? ParentID { get; set; } // int
		[Column(),      Nullable            ] public int? ChildID  { get; set; } // int
		[Column("_ID"), PrimaryKey, Identity] public int  Id       { get; set; } // int
	}

	[Table(Schema="dbo", Name="CollatedTable")]
	public partial class CollatedTable
	{
		[Column, NotNull] public int    Id              { get; set; } // int
		[Column, NotNull] public string CaseSensitive   { get; set; } = null!; // nvarchar(20)
		[Column, NotNull] public string CaseInsensitive { get; set; } = null!; // nvarchar(20)
	}

	[Table(Schema="dbo", Name="CreateIfNotExistsTable")]
	public partial class CreateIfNotExistsTable
	{
		[Column, NotNull] public int Id    { get; set; } // int
		[Column, NotNull] public int Value { get; set; } // int
	}

	[Table(Schema="sys", Name="database_firewall_rules", IsView=true)]
	public partial class sys_DatabaseFirewallRule
	{
		[Column("id"),               Identity] public int      Id             { get; set; } // int
		[Column("name"),             NotNull ] public string   Name           { get; set; } = null!; // nvarchar(128)
		[Column("start_ip_address"), NotNull ] public string   StartIpAddress { get; set; } = null!; // varchar(45)
		[Column("end_ip_address"),   NotNull ] public string   EndIpAddress   { get; set; } = null!; // varchar(45)
		[Column("create_date"),      NotNull ] public DateTime CreateDate     { get; set; } // datetime
		[Column("modify_date"),      NotNull ] public DateTime ModifyDate     { get; set; } // datetime
	}

	[Table(Schema="dbo", Name="DataType")]
	public partial class DataType
	{
		[Column("id"), NotNull] public int Id { get; set; } // int
	}

	[Table(Schema="dbo", Name="DecimalOverflow")]
	public partial class DecimalOverflow
	{
		[PrimaryKey, NotNull    ] public decimal  Decimal1 { get; set; } // decimal(38, 20)
		[Column,        Nullable] public decimal? Decimal2 { get; set; } // decimal(31, 2)
		[Column,        Nullable] public decimal? Decimal3 { get; set; } // decimal(38, 36)
		[Column,        Nullable] public decimal? Decimal4 { get; set; } // decimal(29, 0)
		[Column,        Nullable] public decimal? Decimal5 { get; set; } // decimal(38, 38)
	}

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

		#region Associations

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

		#endregion
	}

	[Table(Schema="dbo", Name="GrandChild")]
	public partial class GrandChild
	{
		[Column(),      Nullable            ] public int? ParentID     { get; set; } // int
		[Column(),      Nullable            ] public int? ChildID      { get; set; } // int
		[Column(),      Nullable            ] public int? GrandChildID { get; set; } // int
		[Column("_ID"), PrimaryKey, Identity] public int  Id           { get; set; } // int
	}

	[Table(Schema="dbo", Name="GuidID")]
	public partial class GuidID
	{
		[PrimaryKey, NotNull    ] public Guid ID     { get; set; } // uniqueidentifier
		[Column,        Nullable] public int? Field1 { get; set; } // int
	}

	[Table(Schema="dbo", Name="GuidID2")]
	public partial class GuidID2
	{
		[PrimaryKey, NotNull] public Guid ID { get; set; } // uniqueidentifier
	}

	[Table(Schema="dbo", Name="IndexTable")]
	public partial class IndexTable
	{
		[PrimaryKey(2), NotNull] public int PKField1    { get; set; } // int
		[PrimaryKey(1), NotNull] public int PKField2    { get; set; } // int
		[Column,        NotNull] public int UniqueField { get; set; } // int
		[Column,        NotNull] public int IndexField  { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_Patient2_IndexTable_BackReference (dbo.IndexTable2)
		/// </summary>
		[Association(ThisKey="PKField2, PKField1", OtherKey="PKField2, PKField1", CanBeNull=true)]
		public IndexTable2? Patient { get; set; }

		#endregion
	}

	[Table(Schema="dbo", Name="IndexTable2")]
	public partial class IndexTable2
	{
		[PrimaryKey(2), NotNull] public int PKField1 { get; set; } // int
		[PrimaryKey(1), NotNull] public int PKField2 { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_Patient2_IndexTable (dbo.IndexTable)
		/// </summary>
		[Association(ThisKey="PKField2, PKField1", OtherKey="PKField2, PKField1", CanBeNull=false)]
		public IndexTable Patient2IndexTable { get; set; } = null!;

		#endregion
	}

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

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

	[Table(Schema="sys", Name="ipv6_database_firewall_rules", IsView=true)]
	public partial class sys_Ipv6DatabaseFirewallRule
	{
		[Column("id"),                 Identity] public int      Id               { get; set; } // int
		[Column("name"),               NotNull ] public string   Name             { get; set; } = null!; // nvarchar(128)
		[Column("start_ipv6_address"), NotNull ] public string   StartIpv6Address { get; set; } = null!; // varchar(45)
		[Column("end_ipv6_address"),   NotNull ] public string   EndIpv6Address   { get; set; } = null!; // varchar(45)
		[Column("create_date"),        NotNull ] public DateTime CreateDate       { get; set; } // datetime
		[Column("modify_date"),        NotNull ] public DateTime ModifyDate       { get; set; } // datetime
	}

	[Table(Schema="dbo", Name="Issue1115")]
	public partial class Issue1115
	{
		[Column("id"), PrimaryKey, NotNull] public SqlHierarchyId Id { get; set; } // hierarchyid
	}

	[Table(Schema="dbo", Name="Issue1144")]
	public partial class Issue1144
	{
		[Column("id"), PrimaryKey, NotNull] public int Id { get; set; } // int
	}

	[Table(Schema="dbo", Name="LinqDataTypes")]
	public partial class LinqDataType
	{
		[Column("_ID"), PrimaryKey, Identity] public int       Id             { get; set; } // int
		[Column(),      Nullable            ] public int?      ID             { get; set; } // int
		[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; } // datetime2(7)
		[Column(),      Nullable            ] public bool?     BoolValue      { get; set; } // bit
		[Column(),      Nullable            ] public Guid?     GuidValue      { get; set; } // uniqueidentifier
		[Column(),      Nullable            ] public byte[]?   BinaryValue    { get; set; } // varbinary(5000)
		[Column(),      Nullable            ] public short?    SmallIntValue  { get; set; } // smallint
		[Column(),      Nullable            ] public int?      IntValue       { get; set; } // int
		[Column(),      Nullable            ] public long?     BigIntValue    { get; set; } // bigint
		[Column(),      Nullable            ] public string?   StringValue    { get; set; } // nvarchar(50)
	}

	[Table(Schema="dbo", Name="Member")]
	public partial class Member
	{
		[PrimaryKey, Identity] public int    MemberId { get; set; } // int
		[Column,     NotNull ] public string Alias    { get; set; } = null!; // nvarchar(50)

		#region Associations

		/// <summary>
		/// FK_Provider_Member_BackReference (dbo.Provider)
		/// </summary>
		[Association(ThisKey="MemberId", OtherKey="ProviderId", CanBeNull=true)]
		public Provider? Provider { get; set; }

		#endregion
	}

	[Table(Schema="dbo", Name="Name.Test")]
	public partial class NameTest
	{
		[Column("Name.Test"), Nullable] public int? NameTestColumn { get; set; } // int
	}

	[Table(Schema="dbo", Name="Parent")]
	public partial class Parent
	{
		[Column(),      Nullable            ] public int? ParentID { get; set; } // int
		[Column(),      Nullable            ] public int? Value1   { get; set; } // int
		[Column("_ID"), PrimaryKey, Identity] public int  Id       { get; set; } // int
	}

	[Table(Schema="dbo", Name="ParentChildView", IsView=true)]
	public partial class ParentChildView
	{
		[Column, Nullable] public int? ParentID { get; set; } // int
		[Column, Nullable] public int? Value1   { get; set; } // int
		[Column, Nullable] public int? ChildID  { get; set; } // int
	}

	[Table(Schema="dbo", Name="ParentView", IsView=true)]
	public partial class ParentView
	{
		[Column(),      Nullable] public int? ParentID { get; set; } // int
		[Column(),      Nullable] public int? Value1   { get; set; } // int
		[Column("_ID"), Identity] public int  Id       { get; set; } // int
	}

	[Table(Schema="dbo", Name="Patient")]
	public partial class Patient
	{
		[PrimaryKey, NotNull] public int    PersonID  { get; set; } // int
		[Column,     NotNull] public string Diagnosis { get; set; } = null!; // nvarchar(256)

		#region Associations

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

		#endregion
	}

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

		#region Associations

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

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

		#endregion
	}

	[Table(Schema="dbo", Name="Provider")]
	public partial class Provider
	{
		[PrimaryKey, NotNull] public int    ProviderId { get; set; } // int
		[Column,     NotNull] public string Test       { get; set; } = null!; // nvarchar(max)

		#region Associations

		/// <summary>
		/// FK_Provider_Member (dbo.Member)
		/// </summary>
		[Association(ThisKey="ProviderId", OtherKey="MemberId", CanBeNull=false)]
		public Member Member { get; set; } = null!;

		#endregion
	}

	[Table(Schema="dbo", Name="SameTableName")]
	public partial class SameTableName
	{
		[Column("id"), Nullable] public int? Id { get; set; } // int
	}

	[Table(Schema="TestSchema", Name="SameTableName")]
	public partial class TestSchema_SameTableName
	{
		[Column("id"), Nullable] public int? Id { get; set; } // int
	}

	[Table(Schema="dbo", Name="SqlTypes")]
	public partial class SqlType
	{
		[PrimaryKey, NotNull    ] public int             ID  { get; set; } // int
		[Column,        Nullable] public SqlHierarchyId? HID { get; set; } // hierarchyid
	}

	[Table(Schema="dbo", Name="TestIdentity")]
	public partial class TestIdentity
	{
		[PrimaryKey, Identity] public int ID { get; set; } // int
	}

	[Table(Schema="dbo", Name="TestMerge1")]
	public partial class TestMerge1
	{
		[PrimaryKey, NotNull    ] public int             Id              { get; set; } // int
		[Column,        Nullable] public int?            Field1          { get; set; } // int
		[Column,        Nullable] public int?            Field2          { get; set; } // int
		[Column,        Nullable] public int?            Field3          { get; set; } // int
		[Column,        Nullable] public int?            Field4          { get; set; } // int
		[Column,        Nullable] public int?            Field5          { get; set; } // int
		[Column,        Nullable] public long?           FieldInt64      { get; set; } // bigint
		[Column,        Nullable] public bool?           FieldBoolean    { get; set; } // bit
		[Column,        Nullable] public string?         FieldString     { get; set; } // varchar(20)
		[Column,        Nullable] public string?         FieldNString    { get; set; } // nvarchar(20)
		[Column,        Nullable] public char?           FieldChar       { get; set; } // char(1)
		[Column,        Nullable] public char?           FieldNChar      { get; set; } // nchar(1)
		[Column,        Nullable] public float?          FieldFloat      { get; set; } // real
		[Column,        Nullable] public double?         FieldDouble     { get; set; } // float
		[Column,        Nullable] public DateTime?       FieldDateTime   { get; set; } // datetime
		[Column,        Nullable] public DateTimeOffset? FieldDateTime2  { get; set; } // datetimeoffset(7)
		[Column,        Nullable] public byte[]?         FieldBinary     { get; set; } // varbinary(20)
		[Column,        Nullable] public Guid?           FieldGuid       { get; set; } // uniqueidentifier
		[Column,        Nullable] public decimal?        FieldDecimal    { get; set; } // decimal(24, 10)
		[Column,        Nullable] public DateTime?       FieldDate       { get; set; } // date
		[Column,        Nullable] public TimeSpan?       FieldTime       { get; set; } // time(7)
		[Column,        Nullable] public string?         FieldEnumString { get; set; } // varchar(20)
		[Column,        Nullable] public int?            FieldEnumNumber { get; set; } // int
	}

	[Table(Schema="dbo", Name="TestMerge2")]
	public partial class TestMerge2
	{
		[PrimaryKey, NotNull    ] public int             Id              { get; set; } // int
		[Column,        Nullable] public int?            Field1          { get; set; } // int
		[Column,        Nullable] public int?            Field2          { get; set; } // int
		[Column,        Nullable] public int?            Field3          { get; set; } // int
		[Column,        Nullable] public int?            Field4          { get; set; } // int
		[Column,        Nullable] public int?            Field5          { get; set; } // int
		[Column,        Nullable] public long?           FieldInt64      { get; set; } // bigint
		[Column,        Nullable] public bool?           FieldBoolean    { get; set; } // bit
		[Column,        Nullable] public string?         FieldString     { get; set; } // varchar(20)
		[Column,        Nullable] public string?         FieldNString    { get; set; } // nvarchar(20)
		[Column,        Nullable] public char?           FieldChar       { get; set; } // char(1)
		[Column,        Nullable] public char?           FieldNChar      { get; set; } // nchar(1)
		[Column,        Nullable] public float?          FieldFloat      { get; set; } // real
		[Column,        Nullable] public double?         FieldDouble     { get; set; } // float
		[Column,        Nullable] public DateTime?       FieldDateTime   { get; set; } // datetime
		[Column,        Nullable] public DateTimeOffset? FieldDateTime2  { get; set; } // datetimeoffset(7)
		[Column,        Nullable] public byte[]?         FieldBinary     { get; set; } // varbinary(20)
		[Column,        Nullable] public Guid?           FieldGuid       { get; set; } // uniqueidentifier
		[Column,        Nullable] public decimal?        FieldDecimal    { get; set; } // decimal(24, 10)
		[Column,        Nullable] public DateTime?       FieldDate       { get; set; } // date
		[Column,        Nullable] public TimeSpan?       FieldTime       { get; set; } // time(7)
		[Column,        Nullable] public string?         FieldEnumString { get; set; } // varchar(20)
		[Column,        Nullable] public int?            FieldEnumNumber { get; set; } // int
	}

	[Table(Schema="dbo", Name="TestMergeIdentity")]
	public partial class TestMergeIdentity
	{
		[PrimaryKey, Identity] public int  Id    { get; set; } // int
		[Column,     Nullable] public int? Field { get; set; } // int
	}

	[Table(Schema="TestSchema", Name="TestSchemaA")]
	public partial class TestSchema_TestSchemaA
	{
		[PrimaryKey, NotNull] public int TestSchemaAID { get; set; } // int
		[Column,     NotNull] public int Field1        { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA2_BackReference (TestSchema.TestSchemaB)
		/// </summary>
		[Association(ThisKey="TestSchemaAID", OtherKey="TargetTestSchemaAId", CanBeNull=true)]
		public IEnumerable<TestSchema_TestSchemaB> FkTestSchemaTestSchemaBYTargetTestSchemaA2BackReferences { get; set; } = null!;

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_OriginTestSchemaA_BackReference (TestSchema.TestSchemaB)
		/// </summary>
		[Association(ThisKey="TestSchemaAID", OtherKey="OriginTestSchemaAID", CanBeNull=true)]
		public IEnumerable<TestSchema_TestSchemaB> TestSchemaBYOriginTestSchemaA { get; set; } = null!;

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA_BackReference (TestSchema.TestSchemaB)
		/// </summary>
		[Association(ThisKey="TestSchemaAID", OtherKey="TargetTestSchemaAID", CanBeNull=true)]
		public IEnumerable<TestSchema_TestSchemaB> TestSchemaBYTargetTestSchemaA { get; set; } = null!;

		#endregion
	}

	[Table(Schema="TestSchema", Name="TestSchemaB")]
	public partial class TestSchema_TestSchemaB
	{
		[Column(),                          PrimaryKey, NotNull] public int TestSchemaBID       { get; set; } // int
		[Column(),                                      NotNull] public int OriginTestSchemaAID { get; set; } // int
		[Column(),                                      NotNull] public int TargetTestSchemaAID { get; set; } // int
		[Column("Target_Test_Schema_A_ID"),             NotNull] public int TargetTestSchemaAId { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA (TestSchema.TestSchemaA)
		/// </summary>
		[Association(ThisKey="TargetTestSchemaAID", OtherKey="TestSchemaAID", CanBeNull=false)]
		public TestSchema_TestSchemaA FKTargetTestSchemaA { get; set; } = null!;

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_OriginTestSchemaA (TestSchema.TestSchemaA)
		/// </summary>
		[Association(ThisKey="OriginTestSchemaAID", OtherKey="TestSchemaAID", CanBeNull=false)]
		public TestSchema_TestSchemaA OriginTestSchemaA { get; set; } = null!;

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA2 (TestSchema.TestSchemaA)
		/// </summary>
		[Association(ThisKey="TargetTestSchemaAId", OtherKey="TestSchemaAID", CanBeNull=false)]
		public TestSchema_TestSchemaA TargetTestSchemaA { get; set; } = null!;

		#endregion
	}

	[Table(Schema="dbo", Name="TestSchema_SameTableName")]
	public partial class TestSchemaSameTableName
	{
		[Column("id"), Nullable] public int? Id { get; set; } // int
	}

	[Table(Schema="dbo", Name="TestSchemaX")]
	public partial class TestSchemaX
	{
		[PrimaryKey, NotNull] public int TestSchemaXID { get; set; } // int
		[Column,     NotNull] public int Field1        { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_TestSchemaY_TestSchemaX_BackReference (dbo.TestSchemaY)
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=true)]
		public IEnumerable<TestSchemaY> TestSchemaY { get; set; } = null!;

		/// <summary>
		/// FK_TestSchemaY_OtherID_BackReference (dbo.TestSchemaY)
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=true)]
		public IEnumerable<TestSchemaY> TestSchemaYOtherIds { get; set; } = null!;

		/// <summary>
		/// FK_TestSchemaY_ParentTestSchemaX_BackReference (dbo.TestSchemaY)
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="ParentTestSchemaXID", CanBeNull=true)]
		public IEnumerable<TestSchemaY> TestSchemaYParentTestSchemaX { get; set; } = null!;

		#endregion
	}

	[Table(Schema="dbo", Name="TestSchemaY")]
	public partial class TestSchemaY
	{
		[Column, NotNull] public int TestSchemaXID       { get; set; } // int
		[Column, NotNull] public int ParentTestSchemaXID { get; set; } // int
		[Column, NotNull] public int OtherID             { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_TestSchemaY_OtherID (dbo.TestSchemaX)
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public TestSchemaX FkTestSchemaYOtherID { get; set; } = null!;

		/// <summary>
		/// FK_TestSchemaY_ParentTestSchemaX (dbo.TestSchemaX)
		/// </summary>
		[Association(ThisKey="ParentTestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public TestSchemaX ParentTestSchemaX { get; set; } = null!;

		/// <summary>
		/// FK_TestSchemaY_TestSchemaX (dbo.TestSchemaX)
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public TestSchemaX TestSchemaX { get; set; } = null!;

		#endregion
	}

	public static partial class TestDataDBStoredProcedures
	{
		#region AddIssue792Record

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

		#endregion

		#region DuplicateColumnNames

		public static IEnumerable<DuplicateColumnNamesResult> DuplicateColumnNames(this TestDataDB dataConnection)
		{
			var ms = dataConnection.MappingSchema;

			return dataConnection.QueryProc(dataReader =>
				new DuplicateColumnNamesResult
				{
					Id      = Converter.ChangeTypeTo<int>   (dataReader.GetValue(0), ms),
					Column2 = Converter.ChangeTypeTo<string>(dataReader.GetValue(1), ms),
				},
				"[dbo].[DuplicateColumnNames]");
		}

		public partial class DuplicateColumnNamesResult
		{
			[Column("id")] public int    Id      { get; set; }
			[Column("id")] public string Column2 { get; set; } = null!;
		}

		#endregion

		#region ExecuteProcIntParameters

		public static int ExecuteProcIntParameters(this TestDataDB dataConnection, int? @input, ref int? @output)
		{
			var parameters = new []
			{
				new DataParameter("@input",  @input,  LinqToDB.DataType.Int32),
				new DataParameter("@output", @output, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				}
			};

			var ret = dataConnection.ExecuteProc("[dbo].[ExecuteProcIntParameters]", parameters);

			@output = Converter.ChangeTypeTo<int?>(parameters[1].Value);

			return ret;
		}

		#endregion

		#region ExecuteProcStringParameters

		/// <summary>
		/// This is &lt;test&gt; procedure!
		/// </summary>
		/// <param name="input">
		/// This is &lt;test&gt; procedure parameter!
		/// </param>
		public static IEnumerable<ExecuteProcStringParametersResult> ExecuteProcStringParameters(this TestDataDB dataConnection, int? @input, ref int? @output)
		{
			var parameters = new []
			{
				new DataParameter("@input",  @input,  LinqToDB.DataType.Int32),
				new DataParameter("@output", @output, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				}
			};

			var ms = dataConnection.MappingSchema;

			var ret = dataConnection.QueryProc(dataReader =>
				new ExecuteProcStringParametersResult
				{
					Column1 = Converter.ChangeTypeTo<string>(dataReader.GetValue(0), ms),
				},
				"[dbo].[ExecuteProcStringParameters]", parameters).ToList();

			@output = Converter.ChangeTypeTo<int?>(parameters[1].Value);

			return ret;
		}

		public partial class ExecuteProcStringParametersResult
		{
			[Column("")] public string Column1 { get; set; } = null!;
		}

		#endregion

		#region Issue1897

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

		#endregion

		#region OutRefEnumTest

		public static int OutRefEnumTest(this TestDataDB dataConnection, string? @str, ref string? @outputStr, ref string? @inputOutputStr)
		{
			var parameters = new []
			{
				new DataParameter("@str",            @str,            LinqToDB.DataType.VarChar)
				{
					Size = 50
				},
				new DataParameter("@outputStr",      @outputStr,      LinqToDB.DataType.VarChar)
				{
					Direction = ParameterDirection.InputOutput,
					Size      = 50
				},
				new DataParameter("@inputOutputStr", @inputOutputStr, LinqToDB.DataType.VarChar)
				{
					Direction = ParameterDirection.InputOutput,
					Size      = 50
				}
			};

			var ret = dataConnection.ExecuteProc("[dbo].[OutRefEnumTest]", parameters);

			@outputStr      = Converter.ChangeTypeTo<string?>(parameters[1].Value);
			@inputOutputStr = Converter.ChangeTypeTo<string?>(parameters[2].Value);

			return ret;
		}

		#endregion

		#region OutRefTest

		public static int OutRefTest(this TestDataDB dataConnection, int? @ID, ref int? @outputID, ref int? @inputOutputID, string? @str, ref string? @outputStr, ref string? @inputOutputStr)
		{
			var parameters = new []
			{
				new DataParameter("@ID",             @ID,             LinqToDB.DataType.Int32),
				new DataParameter("@outputID",       @outputID,       LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				},
				new DataParameter("@inputOutputID",  @inputOutputID,  LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				},
				new DataParameter("@str",            @str,            LinqToDB.DataType.VarChar)
				{
					Size = 50
				},
				new DataParameter("@outputStr",      @outputStr,      LinqToDB.DataType.VarChar)
				{
					Direction = ParameterDirection.InputOutput,
					Size      = 50
				},
				new DataParameter("@inputOutputStr", @inputOutputStr, LinqToDB.DataType.VarChar)
				{
					Direction = ParameterDirection.InputOutput,
					Size      = 50
				}
			};

			var ret = dataConnection.ExecuteProc("[dbo].[OutRefTest]", parameters);

			@outputID       = Converter.ChangeTypeTo<int?>   (parameters[1].Value);
			@inputOutputID  = Converter.ChangeTypeTo<int?>   (parameters[2].Value);
			@outputStr      = Converter.ChangeTypeTo<string?>(parameters[4].Value);
			@inputOutputStr = Converter.ChangeTypeTo<string?>(parameters[5].Value);

			return ret;
		}

		#endregion

		#region PatientSelectAll

		public static IEnumerable<PatientSelectAllResult> PatientSelectAll(this TestDataDB dataConnection)
		{
			return dataConnection.QueryProc<PatientSelectAllResult>("[dbo].[Patient_SelectAll]");
		}

		public partial class PatientSelectAllResult
		{
			public int     PersonID   { get; set; }
			public string  FirstName  { get; set; } = null!;
			public string  LastName   { get; set; } = null!;
			public string? MiddleName { get; set; }
			public char    Gender     { get; set; }
			public string  Diagnosis  { get; set; } = null!;
		}

		#endregion

		#region PatientSelectByName

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

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

		public partial class PatientSelectByNameResult
		{
			public int     PersonID   { get; set; }
			public string  FirstName  { get; set; } = null!;
			public string  LastName   { get; set; } = null!;
			public string? MiddleName { get; set; }
			public char    Gender     { get; set; }
			public string  Diagnosis  { get; set; } = null!;
		}

		#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("[dbo].[Person_Delete]", parameters);
		}

		#endregion

		#region PersonInsert

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

			return dataConnection.QueryProc<PersonInsertResult>("[dbo].[Person_Insert]", parameters);
		}

		public partial class PersonInsertResult
		{
			public int? PersonID { get; set; }
		}

		#endregion

		#region PersonInsertOutputParameter

		public static int PersonInsertOutputParameter(this TestDataDB dataConnection, string? @FirstName, string? @LastName, string? @MiddleName, char? @Gender, ref int? @PersonID)
		{
			var parameters = new []
			{
				new DataParameter("@FirstName", @FirstName, LinqToDB.DataType.NVarChar)
				{
					Size = 50
				},
				new DataParameter("@LastName", @LastName, LinqToDB.DataType.NVarChar)
				{
					Size = 50
				},
				new DataParameter("@MiddleName", @MiddleName, LinqToDB.DataType.NVarChar)
				{
					Size = 50
				},
				new DataParameter("@Gender",   @Gender,   LinqToDB.DataType.Char)
				{
					Size = 1
				},
				new DataParameter("@PersonID", @PersonID, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				}
			};

			var ret = dataConnection.ExecuteProc("[dbo].[Person_Insert_OutputParameter]", parameters);

			@PersonID = Converter.ChangeTypeTo<int?>(parameters[4].Value);

			return ret;
		}

		#endregion

		#region PersonSelectAll

		public static IEnumerable<Person> PersonSelectAll(this TestDataDB dataConnection)
		{
			return dataConnection.QueryProc<Person>("[dbo].[Person_SelectAll]");
		}

		#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>("[dbo].[Person_SelectByKey]", parameters);
		}

		#endregion

		#region PersonSelectByKeyLowercase

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

			return dataConnection.QueryProc<PersonSelectByKeyLowercaseResult>("[dbo].[Person_SelectByKeyLowercase]", parameters);
		}

		public partial class PersonSelectByKeyLowercaseResult
		{
			public int    PersonID  { get; set; }
			public string FirstName { get; set; } = null!;
		}

		#endregion

		#region PersonSelectByName

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

			return dataConnection.QueryProc<Person>("[dbo].[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.NVarChar)
				{
					Size = 50
				},
				new DataParameter("@lastName",  @lastName,  LinqToDB.DataType.NVarChar)
				{
					Size = 50
				}
			};

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

		#endregion

		#region PersonUpdate

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

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

		#endregion

		#region QueryProcMultipleParameters

		public static IEnumerable<Person> QueryProcMultipleParameters(this TestDataDB dataConnection, int? @input, ref int? @output1, ref int? @output2, ref int? @output3)
		{
			var parameters = new []
			{
				new DataParameter("@input",   @input,   LinqToDB.DataType.Int32),
				new DataParameter("@output1", @output1, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				},
				new DataParameter("@output2", @output2, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				},
				new DataParameter("@output3", @output3, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				}
			};

			var ret = dataConnection.QueryProc<Person>("[dbo].[QueryProcMultipleParameters]", parameters).ToList();

			@output1 = Converter.ChangeTypeTo<int?>(parameters[1].Value);
			@output2 = Converter.ChangeTypeTo<int?>(parameters[2].Value);
			@output3 = Converter.ChangeTypeTo<int?>(parameters[3].Value);

			return ret;
		}

		#endregion

		#region QueryProcParameters

		public static IEnumerable<Person> QueryProcParameters(this TestDataDB dataConnection, int? @input, ref int? @output1, ref int? @output2)
		{
			var parameters = new []
			{
				new DataParameter("@input",   @input,   LinqToDB.DataType.Int32),
				new DataParameter("@output1", @output1, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				},
				new DataParameter("@output2", @output2, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.InputOutput
				}
			};

			var ret = dataConnection.QueryProc<Person>("[dbo].[QueryProcParameters]", parameters).ToList();

			@output1 = Converter.ChangeTypeTo<int?>(parameters[1].Value);
			@output2 = Converter.ChangeTypeTo<int?>(parameters[2].Value);

			return ret;
		}

		#endregion

		#region SelectImplicitColumn

		public static IEnumerable<SelectImplicitColumnResult> SelectImplicitColumn(this TestDataDB dataConnection)
		{
			var ms = dataConnection.MappingSchema;

			return dataConnection.QueryProc(dataReader =>
				new SelectImplicitColumnResult
				{
					Column1 = Converter.ChangeTypeTo<int>(dataReader.GetValue(0), ms),
				},
				"[dbo].[SelectImplicitColumn]");
		}

		public partial class SelectImplicitColumnResult
		{
			[Column("")] public int Column1 { get; set; }
		}

		#endregion

		#region TableTypeTestProc

		public static IEnumerable<TableTypeTestProcResult> TableTypeTestProc(this TestDataDB dataConnection, DataTable? @table)
		{
			var parameters = new []
			{
				new DataParameter("@table", @table, LinqToDB.DataType.Structured)
				{
					DbType = "[dbo].[TestTableType]"
				}
			};

			return dataConnection.QueryProc<TableTypeTestProcResult>("[dbo].[TableTypeTestProc]", parameters);
		}

		public partial class TableTypeTestProcResult
		{
			public int?    Id   { get; set; }
			public string? Name { get; set; }
		}

		#endregion

		#region TestProcedure

		public static IEnumerable<TestProcedureResult> TestProcedure(this TestDataDB dataConnection)
		{
			var ms = dataConnection.MappingSchema;

			return dataConnection.QueryProc(dataReader =>
				new TestProcedureResult
				{
					Column1 = Converter.ChangeTypeTo<int>(dataReader.GetValue(0), ms),
				},
				"[TestSchema].[TestProcedure]");
		}

		public partial class TestProcedureResult
		{
			[Column("")] public int Column1 { get; set; }
		}

		#endregion

		#region VariableResults

		public static IEnumerable<VariableResultsResult> VariableResults(this TestDataDB dataConnection, bool? @ReturnFullRow)
		{
			var parameters = new []
			{
				new DataParameter("@ReturnFullRow", @ReturnFullRow, LinqToDB.DataType.Boolean)
			};

			return dataConnection.QueryProc<VariableResultsResult>("[dbo].[VariableResults]", parameters);
		}

		public partial class VariableResultsResult
		{
			public int    Code   { get; set; }
			public string Value1 { get; set; } = null!;
			public string Value2 { get; set; } = null!;
		}

		#endregion
	}

	public static partial class SqlFunctions
	{
		#region ScalarFunction

		/// <summary>
		/// This is &lt;test&gt; scalar function!
		/// </summary>
		/// <param name="value">
		/// This is &lt;test&gt; scalar function parameter!
		/// </param>
		[Sql.Function(Name="[dbo].[ScalarFunction]", ServerSideOnly=true)]
		public static int? ScalarFunction(int? @value)
		{
			throw new InvalidOperationException();
		}

		#endregion
	}

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

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

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

		public static DecimalOverflow? Find(this ITable<DecimalOverflow> table, decimal Decimal1)
		{
			return table.FirstOrDefault(t =>
				t.Decimal1 == Decimal1);
		}

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

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

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

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

		public static IndexTable? Find(this ITable<IndexTable> table, int PKField1, int PKField2)
		{
			return table.FirstOrDefault(t =>
				t.PKField1 == PKField1 &&
				t.PKField2 == PKField2);
		}

		public static IndexTable2? Find(this ITable<IndexTable2> table, int PKField1, int PKField2)
		{
			return table.FirstOrDefault(t =>
				t.PKField1 == PKField1 &&
				t.PKField2 == PKField2);
		}

		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 Issue1115? Find(this ITable<Issue1115> table, SqlHierarchyId Id)
		{
			return table.FirstOrDefault(t =>
				(bool)(t.Id == Id));
		}

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

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

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

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

		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 Provider? Find(this ITable<Provider> table, int ProviderId)
		{
			return table.FirstOrDefault(t =>
				t.ProviderId == ProviderId);
		}

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

		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);
		}

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

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

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

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