//---------------------------------------------------------------------------------------------------
// <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 Sql2017ProcSchema
{
	public partial class NorthwindDB : LinqToDB.Data.DataConnection
	{
		public ITable<AlphabeticalListOfProduct>  AlphabeticalListOfProducts   { get { return this.GetTable<AlphabeticalListOfProduct>(); } }
		public ITable<Category>                   Categories                   { get { return this.GetTable<Category>(); } }
		public ITable<CategorySalesFor1997>       CategorySalesFor1997         { get { return this.GetTable<CategorySalesFor1997>(); } }
		public ITable<CurrentProductList>         CurrentProductLists          { get { return this.GetTable<CurrentProductList>(); } }
		public ITable<Customer>                   Customers                    { get { return this.GetTable<Customer>(); } }
		public ITable<CustomerAndSuppliersByCity> CustomerAndSuppliersByCities { get { return this.GetTable<CustomerAndSuppliersByCity>(); } }
		public ITable<CustomerCustomerDemo>       CustomerCustomerDemoes       { get { return this.GetTable<CustomerCustomerDemo>(); } }
		public ITable<CustomerDemographic>        CustomerDemographics         { get { return this.GetTable<CustomerDemographic>(); } }
		public ITable<Employee>                   Employees                    { get { return this.GetTable<Employee>(); } }
		public ITable<EmployeeTerritory>          EmployeeTerritories          { get { return this.GetTable<EmployeeTerritory>(); } }
		public ITable<Invoice>                    Invoices                     { get { return this.GetTable<Invoice>(); } }
		public ITable<Order>                      Orders                       { get { return this.GetTable<Order>(); } }
		public ITable<OrderDetail>                OrderDetails                 { get { return this.GetTable<OrderDetail>(); } }
		public ITable<OrderDetailsExtended>       OrderDetailsExtendeds        { get { return this.GetTable<OrderDetailsExtended>(); } }
		public ITable<OrdersQry>                  OrdersQries                  { get { return this.GetTable<OrdersQry>(); } }
		public ITable<OrderSubtotal>              OrderSubtotals               { get { return this.GetTable<OrderSubtotal>(); } }
		public ITable<ProductsAboveAveragePrice>  ProductsAboveAveragePrices   { get { return this.GetTable<ProductsAboveAveragePrice>(); } }
		public ITable<ProductSalesFor1997>        ProductSalesFor1997          { get { return this.GetTable<ProductSalesFor1997>(); } }
		public ITable<ProductsByCategory>         ProductsByCategories         { get { return this.GetTable<ProductsByCategory>(); } }
		public ITable<QuarterlyOrder>             QuarterlyOrders              { get { return this.GetTable<QuarterlyOrder>(); } }
		public ITable<Region>                     Regions                      { get { return this.GetTable<Region>(); } }
		public ITable<SalesByCategory>            SalesByCategories            { get { return this.GetTable<SalesByCategory>(); } }
		public ITable<SalesTotalsByAmount>        SalesTotalsByAmounts         { get { return this.GetTable<SalesTotalsByAmount>(); } }
		public ITable<Shipper>                    Shippers                     { get { return this.GetTable<Shipper>(); } }
		public ITable<SummaryOfSalesByQuarter>    SummaryOfSalesByQuarters     { get { return this.GetTable<SummaryOfSalesByQuarter>(); } }
		public ITable<SummaryOfSalesByYear>       SummaryOfSalesByYears        { get { return this.GetTable<SummaryOfSalesByYear>(); } }
		public ITable<Supplier>                   Suppliers                    { get { return this.GetTable<Supplier>(); } }
		public ITable<Territory>                  Territories                  { get { return this.GetTable<Territory>(); } }

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

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

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

		#region Alias members

		[Obsolete("Use Categories instead.")  ] public ITable<Category>    CATEG         { get { return Categories; } }
		[Obsolete("Use OrderDetails instead.")] public ITable<OrderDetail> Order_Details { get { return OrderDetails; } }

		#endregion
	}

	[Table("Alphabetical list of products", IsView=true)]
	public partial class AlphabeticalListOfProduct
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int      ProductID       { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string   ProductName     { get; set; } = null!; // nvarchar(40)
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                  Nullable] public int?     SupplierID      { get; set; } // int
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                  Nullable] public int?     CategoryID      { get; set; } // int
		[Column(DbType="nvarchar(20)", DataType=LinqToDB.DataType.NVarChar, Length=20),    Nullable] public string?  QuantityPerUnit { get; set; } // nvarchar(20)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal? UnitPrice       { get; set; } // money
		[Column(DbType="smallint",     DataType=LinqToDB.DataType.Int16),                  Nullable] public short?   UnitsInStock    { get; set; } // smallint
		[Column(DbType="smallint",     DataType=LinqToDB.DataType.Int16),                  Nullable] public short?   UnitsOnOrder    { get; set; } // smallint
		[Column(DbType="smallint",     DataType=LinqToDB.DataType.Int16),                  Nullable] public short?   ReorderLevel    { get; set; } // smallint
		[Column(DbType="bit",          DataType=LinqToDB.DataType.Boolean),             NotNull    ] public bool     Discontinued    { get; set; } // bit
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), NotNull    ] public string   CategoryName    { get; set; } = null!; // nvarchar(15)
	}

	[Table("Categories")]
	public partial class Category
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               SequenceName("https://github.com/linq2db/linq2db/issues/1866"), PrimaryKey, Identity] public int     CategoryID   { get; set; } // int
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), NotNull                                                                             ] public string  CategoryName { get; set; } = null!; // nvarchar(15)
		[Column(DbType="ntext",        DataType=LinqToDB.DataType.NText),                  Nullable                                                                         ] public string? Description  { get; set; } // ntext
		[Column(DbType="image",        DataType=LinqToDB.DataType.Image),                  Nullable                                                                         ] public byte[]? Picture      { get; set; } // image
	}

	[Obsolete("Use Category instead.")]
	public partial class CATEG : Category
	{
	}

	[Table("Category Sales for 1997", IsView=true)]
	public partial class CategorySalesFor1997
	{
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), NotNull    ] public string   CategoryName  { get; set; } = null!; // nvarchar(15)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal? CategorySales { get; set; } // money
	}

	[Table("Current Product List", IsView=true)]
	public partial class CurrentProductList
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               Identity] public int    ProductID   { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull ] public string ProductName { get; set; } = null!; // nvarchar(40)
	}

	[Table("Customers")]
	public partial class Customer
	{
		[Column(DbType="nchar(5)",     DataType=LinqToDB.DataType.NChar,    Length=5),  PrimaryKey,  NotNull] public string  CustomerID   { get; set; } = null!; // nchar(5)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40),              NotNull] public string  CompanyName  { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(30)", DataType=LinqToDB.DataType.NVarChar, Length=30),    Nullable         ] public string? ContactName  { get; set; } // nvarchar(30)
		[Column(DbType="nvarchar(30)", DataType=LinqToDB.DataType.NVarChar, Length=30),    Nullable         ] public string? ContactTitle { get; set; } // nvarchar(30)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60),    Nullable         ] public string? Address      { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable         ] public string? City         { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable         ] public string? Region       { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10),    Nullable         ] public string? PostalCode   { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable         ] public string? Country      { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(24)", DataType=LinqToDB.DataType.NVarChar, Length=24),    Nullable         ] public string? Phone        { get; set; } // nvarchar(24)
		[Column(DbType="nvarchar(24)", DataType=LinqToDB.DataType.NVarChar, Length=24),    Nullable         ] public string? Fax          { get; set; } // nvarchar(24)

		#region Associations

		/// <summary>
		/// FK_CustomerCustomerDemo_Customers_BackReference (dbo.CustomerCustomerDemo)
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public List<CustomerCustomerDemo> CustomerCustomerDemoes { get; set; } = null!;

		/// <summary>
		/// FK_Orders_Customers_BackReference (dbo.Orders)
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public List<Order> Orders { get; set; } = null!;

		#endregion
	}

	[Table("Customer and Suppliers by City", IsView=true)]
	public partial class CustomerAndSuppliersByCity
	{
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string? City         { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string  CompanyName  { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(30)", DataType=LinqToDB.DataType.NVarChar, Length=30),    Nullable] public string? ContactName  { get; set; } // nvarchar(30)
		[Column(DbType="varchar(9)",   DataType=LinqToDB.DataType.VarChar,  Length=9),  NotNull    ] public string  Relationship { get; set; } = null!; // varchar(9)
	}

	[Table("CustomerCustomerDemo")]
	public partial class CustomerCustomerDemo
	{
		[Column(DbType="nchar(5)",  DataType=LinqToDB.DataType.NChar, Length=5),  PrimaryKey(1), NotNull] public string CustomerID     { get; set; } = null!; // nchar(5)
		[Column(DbType="nchar(10)", DataType=LinqToDB.DataType.NChar, Length=10), PrimaryKey(2), NotNull] public string CustomerTypeID { get; set; } = null!; // nchar(10)

		#region Associations

		/// <summary>
		/// FK_CustomerCustomerDemo_Customers (dbo.Customers)
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=false)]
		public Customer Customer { get; set; } = null!;

		/// <summary>
		/// FK_CustomerCustomerDemo (dbo.CustomerDemographics)
		/// </summary>
		[Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID", CanBeNull=false)]
		public CustomerDemographic CustomerType { get; set; } = null!;

		#endregion
	}

	[Table("CustomerDemographics")]
	public partial class CustomerDemographic
	{
		[Column(DbType="nchar(10)", DataType=LinqToDB.DataType.NChar, Length=10), PrimaryKey,  NotNull] public string  CustomerTypeID { get; set; } = null!; // nchar(10)
		[Column(DbType="ntext",     DataType=LinqToDB.DataType.NText),               Nullable         ] public string? CustomerDesc   { get; set; } // ntext

		#region Associations

		/// <summary>
		/// FK_CustomerCustomerDemo_BackReference (dbo.CustomerCustomerDemo)
		/// </summary>
		[Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID", CanBeNull=true)]
		public List<CustomerCustomerDemo> CustomerCustomerDemoes { get; set; } = null!;

		#endregion
	}

	[Table("Employees")]
	public partial class Employee
	{
		[Column(DbType="int",           DataType=LinqToDB.DataType.Int32),                PrimaryKey,  Identity] public int       EmployeeID      { get; set; } // int
		[Column(DbType="nvarchar(20)",  DataType=LinqToDB.DataType.NVarChar, Length=20),  NotNull              ] public string    LastName        { get; set; } = null!; // nvarchar(20)
		[Column(DbType="nvarchar(10)",  DataType=LinqToDB.DataType.NVarChar, Length=10),  NotNull              ] public string    FirstName       { get; set; } = null!; // nvarchar(10)
		[Column(DbType="nvarchar(30)",  DataType=LinqToDB.DataType.NVarChar, Length=30),     Nullable          ] public string?   Title           { get; set; } // nvarchar(30)
		[Column(DbType="nvarchar(25)",  DataType=LinqToDB.DataType.NVarChar, Length=25),     Nullable          ] public string?   TitleOfCourtesy { get; set; } // nvarchar(25)
		[Column(DbType="datetime",      DataType=LinqToDB.DataType.DateTime),                Nullable          ] public DateTime? BirthDate       { get; set; } // datetime
		[Column(DbType="datetime",      DataType=LinqToDB.DataType.DateTime),                Nullable          ] public DateTime? HireDate        { get; set; } // datetime
		[Column(DbType="nvarchar(60)",  DataType=LinqToDB.DataType.NVarChar, Length=60),     Nullable          ] public string?   Address         { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)",  DataType=LinqToDB.DataType.NVarChar, Length=15),     Nullable          ] public string?   City            { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)",  DataType=LinqToDB.DataType.NVarChar, Length=15),     Nullable          ] public string?   Region          { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)",  DataType=LinqToDB.DataType.NVarChar, Length=10),     Nullable          ] public string?   PostalCode      { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)",  DataType=LinqToDB.DataType.NVarChar, Length=15),     Nullable          ] public string?   Country         { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(24)",  DataType=LinqToDB.DataType.NVarChar, Length=24),     Nullable          ] public string?   HomePhone       { get; set; } // nvarchar(24)
		[Column(DbType="nvarchar(4)",   DataType=LinqToDB.DataType.NVarChar, Length=4),      Nullable          ] public string?   Extension       { get; set; } // nvarchar(4)
		[Column(DbType="image",         DataType=LinqToDB.DataType.Image),                   Nullable          ] public byte[]?   Photo           { get; set; } // image
		[Column(DbType="ntext",         DataType=LinqToDB.DataType.NText),                   Nullable          ] public string?   Notes           { get; set; } // ntext
		[Column(DbType="int",           DataType=LinqToDB.DataType.Int32),                   Nullable          ] public int?      ReportsTo       { get; set; } // int
		[Column(DbType="nvarchar(255)", DataType=LinqToDB.DataType.NVarChar, Length=255),    Nullable          ] public string?   PhotoPath       { get; set; } // nvarchar(255)

		#region Associations

		/// <summary>
		/// FK_EmployeeTerritories_Employees_BackReference (dbo.EmployeeTerritories)
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public List<EmployeeTerritory> EmployeeTerritories { get; set; } = null!;

		/// <summary>
		/// FK_Employees_Employees (dbo.Employees)
		/// </summary>
		[Association(ThisKey="ReportsTo", OtherKey="EmployeeID", CanBeNull=true)]
		public Employee? FkEmployeesEmployee { get; set; }

		/// <summary>
		/// FK_Employees_Employees_BackReference (dbo.Employees)
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="ReportsTo", CanBeNull=true)]
		public List<Employee> FkEmployeesEmployeesBackReferences { get; set; } = null!;

		/// <summary>
		/// FK_Orders_Employees_BackReference (dbo.Orders)
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public List<Order> Orders { get; set; } = null!;

		#endregion
	}

	[Table("EmployeeTerritories")]
	public partial class EmployeeTerritory
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey(1), NotNull] public int    EmployeeID  { get; set; } // int
		[Column(DbType="nvarchar(20)", DataType=LinqToDB.DataType.NVarChar, Length=20), PrimaryKey(2), NotNull] public string TerritoryID { get; set; } = null!; // nvarchar(20)

		#region Associations

		/// <summary>
		/// FK_EmployeeTerritories_Employees (dbo.Employees)
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=false)]
		public Employee Employee { get; set; } = null!;

		/// <summary>
		/// FK_EmployeeTerritories_Territories (dbo.Territories)
		/// </summary>
		[Association(ThisKey="TerritoryID", OtherKey="TerritoryID", CanBeNull=false)]
		public Territory Territory { get; set; } = null!;

		#endregion
	}

	[Table("Invoices", IsView=true)]
	public partial class Invoice
	{
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40),    Nullable] public string?   ShipName       { get; set; } // nvarchar(40)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60),    Nullable] public string?   ShipAddress    { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   ShipCity       { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   ShipRegion     { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10),    Nullable] public string?   ShipPostalCode { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   ShipCountry    { get; set; } // nvarchar(15)
		[Column(DbType="nchar(5)",     DataType=LinqToDB.DataType.NChar,    Length=5),     Nullable] public string?   CustomerID     { get; set; } // nchar(5)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string    CustomerName   { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60),    Nullable] public string?   Address        { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   City           { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   Region         { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10),    Nullable] public string?   PostalCode     { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   Country        { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(31)", DataType=LinqToDB.DataType.NVarChar, Length=31), NotNull    ] public string    Salesperson    { get; set; } = null!; // nvarchar(31)
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int       OrderID        { get; set; } // int
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? OrderDate      { get; set; } // datetime
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? RequiredDate   { get; set; } // datetime
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? ShippedDate    { get; set; } // datetime
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string    ShipperName    { get; set; } = null!; // nvarchar(40)
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int       ProductID      { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string    ProductName    { get; set; } = null!; // nvarchar(40)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),               NotNull    ] public decimal   UnitPrice      { get; set; } // money
		[Column(DbType="smallint",     DataType=LinqToDB.DataType.Int16),               NotNull    ] public short     Quantity       { get; set; } // smallint
		[Column(DbType="real",         DataType=LinqToDB.DataType.Single),              NotNull    ] public float     Discount       { get; set; } // real
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal?  ExtendedPrice  { get; set; } // money
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal?  Freight        { get; set; } // money
	}

	[Table("Orders")]
	public partial class Order
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey, Identity] public int       OrderID        { get; set; } // int
		[Column(DbType="nchar(5)",     DataType=LinqToDB.DataType.NChar,    Length=5),  Nullable            ] public string?   CustomerID     { get; set; } // nchar(5)
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               Nullable            ] public int?      EmployeeID     { get; set; } // int
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),            Nullable            ] public DateTime? OrderDate      { get; set; } // datetime
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),            Nullable            ] public DateTime? RequiredDate   { get; set; } // datetime
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),            Nullable            ] public DateTime? ShippedDate    { get; set; } // datetime
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               Nullable            ] public int?      ShipVia        { get; set; } // int
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),               Nullable            ] public decimal?  Freight        { get; set; } // money
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), Nullable            ] public string?   ShipName       { get; set; } // nvarchar(40)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60), Nullable            ] public string?   ShipAddress    { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), Nullable            ] public string?   ShipCity       { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), Nullable            ] public string?   ShipRegion     { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10), Nullable            ] public string?   ShipPostalCode { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), Nullable            ] public string?   ShipCountry    { get; set; } // nvarchar(15)

		#region Associations

		/// <summary>
		/// FK_Orders_Customers (dbo.Customers)
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public Customer? Customer { get; set; }

		/// <summary>
		/// FK_Orders_Employees (dbo.Employees)
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public Employee? Employee { get; set; }

		/// <summary>
		/// FK_Order_Details_Orders_BackReference (dbo.Order Details)
		/// </summary>
		[Association(ThisKey="OrderID", OtherKey="ID", CanBeNull=true)]
		public List<OrderDetail> OrderDetails { get; set; } = null!;

		/// <summary>
		/// FK_Orders_Shippers (dbo.Shippers)
		/// </summary>
		[Association(ThisKey="ShipVia", OtherKey="ShipperID", CanBeNull=true)]
		public Shipper? Shipper { get; set; }

		#endregion
	}

	[Table("Order Details")]
	public partial class OrderDetail
	{
		[Column("OrderID", DbType="int",      DataType=LinqToDB.DataType.Int32),  PrimaryKey(1), NotNull] public int     ID        { get; set; } // int
		[Column(           DbType="int",      DataType=LinqToDB.DataType.Int32),  PrimaryKey(2), NotNull] public int     ProductID { get; set; } // int
		[Column(           DbType="money",    DataType=LinqToDB.DataType.Money),                 NotNull] public decimal UnitPrice { get; set; } // money
		[Column(           DbType="smallint", DataType=LinqToDB.DataType.Int16),                 NotNull] public short   Quantity  { get; set; } // smallint
		[Column(           DbType="real",     DataType=LinqToDB.DataType.Single),                NotNull] public float   Discount  { get; set; } // real

		#region Associations

		/// <summary>
		/// FK_Order_Details_Orders (dbo.Orders)
		/// </summary>
		[Association(ThisKey="ID", OtherKey="OrderID", CanBeNull=false)]
		public Order Order { get; set; } = null!;

		#endregion
	}

	[Obsolete("Use OrderDetail instead.")]
	public partial class ORD_DET : OrderDetail
	{
	}

	[Table("Order Details Extended", IsView=true)]
	public partial class OrderDetailsExtended
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int      OrderID       { get; set; } // int
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int      ProductID     { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string   ProductName   { get; set; } = null!; // nvarchar(40)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),               NotNull    ] public decimal  UnitPrice     { get; set; } // money
		[Column(DbType="smallint",     DataType=LinqToDB.DataType.Int16),               NotNull    ] public short    Quantity      { get; set; } // smallint
		[Column(DbType="real",         DataType=LinqToDB.DataType.Single),              NotNull    ] public float    Discount      { get; set; } // real
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal? ExtendedPrice { get; set; } // money
	}

	[Table("Orders Qry", IsView=true)]
	public partial class OrdersQry
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int       OrderID        { get; set; } // int
		[Column(DbType="nchar(5)",     DataType=LinqToDB.DataType.NChar,    Length=5),     Nullable] public string?   CustomerID     { get; set; } // nchar(5)
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                  Nullable] public int?      EmployeeID     { get; set; } // int
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? OrderDate      { get; set; } // datetime
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? RequiredDate   { get; set; } // datetime
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? ShippedDate    { get; set; } // datetime
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                  Nullable] public int?      ShipVia        { get; set; } // int
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal?  Freight        { get; set; } // money
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40),    Nullable] public string?   ShipName       { get; set; } // nvarchar(40)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60),    Nullable] public string?   ShipAddress    { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   ShipCity       { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   ShipRegion     { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10),    Nullable] public string?   ShipPostalCode { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   ShipCountry    { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string    CompanyName    { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60),    Nullable] public string?   Address        { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   City           { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   Region         { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10),    Nullable] public string?   PostalCode     { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable] public string?   Country        { get; set; } // nvarchar(15)
	}

	[Table("Order Subtotals", IsView=true)]
	public partial class OrderSubtotal
	{
		[Column(DbType="int",   DataType=LinqToDB.DataType.Int32), NotNull    ] public int      OrderID  { get; set; } // int
		[Column(DbType="money", DataType=LinqToDB.DataType.Money),    Nullable] public decimal? Subtotal { get; set; } // money
	}

	[Table("Products Above Average Price", IsView=true)]
	public partial class ProductsAboveAveragePrice
	{
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string   ProductName { get; set; } = null!; // nvarchar(40)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal? UnitPrice   { get; set; } // money
	}

	[Table("Product Sales for 1997", IsView=true)]
	public partial class ProductSalesFor1997
	{
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), NotNull    ] public string   CategoryName { get; set; } = null!; // nvarchar(15)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string   ProductName  { get; set; } = null!; // nvarchar(40)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal? ProductSales { get; set; } // money
	}

	[Table("Products by Category", IsView=true)]
	public partial class ProductsByCategory
	{
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), NotNull    ] public string  CategoryName    { get; set; } = null!; // nvarchar(15)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string  ProductName     { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(20)", DataType=LinqToDB.DataType.NVarChar, Length=20),    Nullable] public string? QuantityPerUnit { get; set; } // nvarchar(20)
		[Column(DbType="smallint",     DataType=LinqToDB.DataType.Int16),                  Nullable] public short?  UnitsInStock    { get; set; } // smallint
		[Column(DbType="bit",          DataType=LinqToDB.DataType.Boolean),             NotNull    ] public bool    Discontinued    { get; set; } // bit
	}

	[Table("Quarterly Orders", IsView=true)]
	public partial class QuarterlyOrder
	{
		[Column(DbType="nchar(5)",     DataType=LinqToDB.DataType.NChar,    Length=5),  Nullable] public string? CustomerID  { get; set; } // nchar(5)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), Nullable] public string? CompanyName { get; set; } // nvarchar(40)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), Nullable] public string? City        { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), Nullable] public string? Country     { get; set; } // nvarchar(15)
	}

	[Table("Region")]
	public partial class Region
	{
		[Column(DbType="int",       DataType=LinqToDB.DataType.Int32),            PrimaryKey, NotNull] public int    RegionID          { get; set; } // int
		[Column(DbType="nchar(50)", DataType=LinqToDB.DataType.NChar, Length=50),             NotNull] public string RegionDescription { get; set; } = null!; // nchar(50)

		#region Associations

		/// <summary>
		/// FK_Territories_Region_BackReference (dbo.Territories)
		/// </summary>
		[Association(ThisKey="RegionID", OtherKey="RegionID", CanBeNull=true)]
		public List<Territory> Territories { get; set; } = null!;

		#endregion
	}

	[Table("Sales by Category", IsView=true)]
	public partial class SalesByCategory
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int      CategoryID   { get; set; } // int
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15), NotNull    ] public string   CategoryName { get; set; } = null!; // nvarchar(15)
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string   ProductName  { get; set; } = null!; // nvarchar(40)
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal? ProductSales { get; set; } // money
	}

	[Table("Sales Totals by Amount", IsView=true)]
	public partial class SalesTotalsByAmount
	{
		[Column(DbType="money",        DataType=LinqToDB.DataType.Money),                  Nullable] public decimal?  SaleAmount  { get; set; } // money
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull    ] public int       OrderID     { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull    ] public string    CompanyName { get; set; } = null!; // nvarchar(40)
		[Column(DbType="datetime",     DataType=LinqToDB.DataType.DateTime),               Nullable] public DateTime? ShippedDate { get; set; } // datetime
	}

	[Table("Shippers")]
	public partial class Shipper
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey,  Identity] public int     ShipperID   { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull              ] public string  CompanyName { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(24)", DataType=LinqToDB.DataType.NVarChar, Length=24),    Nullable          ] public string? Phone       { get; set; } // nvarchar(24)

		#region Associations

		/// <summary>
		/// FK_Orders_Shippers_BackReference (dbo.Orders)
		/// </summary>
		[Association(ThisKey="ShipperID", OtherKey="ShipVia", CanBeNull=true)]
		public List<Order> Orders { get; set; } = null!;

		#endregion
	}

	[Table("Summary of Sales by Quarter", IsView=true)]
	public partial class SummaryOfSalesByQuarter
	{
		[Column(DbType="datetime", DataType=LinqToDB.DataType.DateTime),    Nullable] public DateTime? ShippedDate { get; set; } // datetime
		[Column(DbType="int",      DataType=LinqToDB.DataType.Int32),    NotNull    ] public int       OrderID     { get; set; } // int
		[Column(DbType="money",    DataType=LinqToDB.DataType.Money),       Nullable] public decimal?  Subtotal    { get; set; } // money
	}

	[Table("Summary of Sales by Year", IsView=true)]
	public partial class SummaryOfSalesByYear
	{
		[Column(DbType="datetime", DataType=LinqToDB.DataType.DateTime),    Nullable] public DateTime? ShippedDate { get; set; } // datetime
		[Column(DbType="int",      DataType=LinqToDB.DataType.Int32),    NotNull    ] public int       OrderID     { get; set; } // int
		[Column(DbType="money",    DataType=LinqToDB.DataType.Money),       Nullable] public decimal?  Subtotal    { get; set; } // money
	}

	[Table("Suppliers")]
	public partial class Supplier
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey,  Identity] public int     SupplierID   { get; set; } // int
		[Column(DbType="nvarchar(40)", DataType=LinqToDB.DataType.NVarChar, Length=40), NotNull              ] public string  CompanyName  { get; set; } = null!; // nvarchar(40)
		[Column(DbType="nvarchar(30)", DataType=LinqToDB.DataType.NVarChar, Length=30),    Nullable          ] public string? ContactName  { get; set; } // nvarchar(30)
		[Column(DbType="nvarchar(30)", DataType=LinqToDB.DataType.NVarChar, Length=30),    Nullable          ] public string? ContactTitle { get; set; } // nvarchar(30)
		[Column(DbType="nvarchar(60)", DataType=LinqToDB.DataType.NVarChar, Length=60),    Nullable          ] public string? Address      { get; set; } // nvarchar(60)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable          ] public string? City         { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable          ] public string? Region       { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(10)", DataType=LinqToDB.DataType.NVarChar, Length=10),    Nullable          ] public string? PostalCode   { get; set; } // nvarchar(10)
		[Column(DbType="nvarchar(15)", DataType=LinqToDB.DataType.NVarChar, Length=15),    Nullable          ] public string? Country      { get; set; } // nvarchar(15)
		[Column(DbType="nvarchar(24)", DataType=LinqToDB.DataType.NVarChar, Length=24),    Nullable          ] public string? Phone        { get; set; } // nvarchar(24)
		[Column(DbType="nvarchar(24)", DataType=LinqToDB.DataType.NVarChar, Length=24),    Nullable          ] public string? Fax          { get; set; } // nvarchar(24)
		[Column(DbType="ntext",        DataType=LinqToDB.DataType.NText),                  Nullable          ] public string? HomePage     { get; set; } // ntext
	}

	[Table("Territories")]
	public partial class Territory
	{
		[Column(DbType="nvarchar(20)", DataType=LinqToDB.DataType.NVarChar, Length=20), PrimaryKey, NotNull] public string TerritoryID          { get; set; } = null!; // nvarchar(20)
		[Column(DbType="nchar(50)",    DataType=LinqToDB.DataType.NChar,    Length=50),             NotNull] public string TerritoryDescription { get; set; } = null!; // nchar(50)
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                           NotNull] public int    RegionID             { get; set; } // int

		#region Associations

		/// <summary>
		/// FK_EmployeeTerritories_Territories_BackReference (dbo.EmployeeTerritories)
		/// </summary>
		[Association(ThisKey="TerritoryID", OtherKey="TerritoryID", CanBeNull=true)]
		public List<EmployeeTerritory> EmployeeTerritories { get; set; } = null!;

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

		#endregion
	}

	public static partial class NorthwindDBStoredProcedures
	{
		#region CustOrderHist

		public static List<CustOrderHistResult> CustOrderHist(this NorthwindDB dataConnection, string? @CustomerID)
		{
			var parameters = new []
			{
				new DataParameter("@CustomerID", @CustomerID, LinqToDB.DataType.NChar)
				{
					Size = 5
				}
			};

			return dataConnection.QueryProc<CustOrderHistResult>("[CustOrderHist]", parameters).ToList();
		}

		public partial class CustOrderHistResult
		{
			public string ProductName { get; set; } = null!;
			public int?   Total       { get; set; }
		}

		#endregion

		#region CustOrdersDetail

		public static List<CustOrdersDetailResult> CustOrdersDetail(this NorthwindDB dataConnection, int? @OrderID)
		{
			var parameters = new []
			{
				new DataParameter("@OrderID", @OrderID, LinqToDB.DataType.Int32)
			};

			return dataConnection.QueryProc<CustOrdersDetailResult>("[CustOrdersDetail]", parameters).ToList();
		}

		public partial class CustOrdersDetailResult
		{
			public string   ProductName   { get; set; } = null!;
			public decimal  UnitPrice     { get; set; }
			public short    Quantity      { get; set; }
			public int?     Discount      { get; set; }
			public decimal? ExtendedPrice { get; set; }
		}

		#endregion

		#region CustOrdersOrders

		public static List<CustOrdersOrdersResult> CustOrdersOrders(this NorthwindDB dataConnection, string? @CustomerID)
		{
			var parameters = new []
			{
				new DataParameter("@CustomerID", @CustomerID, LinqToDB.DataType.NChar)
				{
					Size = 5
				}
			};

			return dataConnection.QueryProc<CustOrdersOrdersResult>("[CustOrdersOrders]", parameters).ToList();
		}

		public partial class CustOrdersOrdersResult
		{
			public int       OrderID      { get; set; }
			public DateTime? OrderDate    { get; set; }
			public DateTime? RequiredDate { get; set; }
			public DateTime? ShippedDate  { get; set; }
		}

		#endregion

		#region EmployeeSalesByCountry

		public static List<EmployeeSalesByCountryResult> EmployeeSalesByCountry(this NorthwindDB dataConnection, DateTime? @BeginningDate, DateTime? @EndingDate)
		{
			var parameters = new []
			{
				new DataParameter("@Beginning_Date", @BeginningDate, LinqToDB.DataType.DateTime),
				new DataParameter("@Ending_Date",    @EndingDate,    LinqToDB.DataType.DateTime)
			};

			return dataConnection.QueryProc<EmployeeSalesByCountryResult>("[Employee Sales by Country]", parameters).ToList();
		}

		public partial class EmployeeSalesByCountryResult
		{
			public string?   Country     { get; set; }
			public string    LastName    { get; set; } = null!;
			public string    FirstName   { get; set; } = null!;
			public DateTime? ShippedDate { get; set; }
			public int       OrderID     { get; set; }
			public decimal?  SaleAmount  { get; set; }
		}

		#endregion

		#region SalesByYear

		public static List<SalesByYearResult> SalesByYear(this NorthwindDB dataConnection, DateTime? @BeginningDate, DateTime? @EndingDate)
		{
			var parameters = new []
			{
				new DataParameter("@Beginning_Date", @BeginningDate, LinqToDB.DataType.DateTime),
				new DataParameter("@Ending_Date",    @EndingDate,    LinqToDB.DataType.DateTime)
			};

			return dataConnection.QueryProc<SalesByYearResult>("[Sales by Year]", parameters).ToList();
		}

		public partial class SalesByYearResult
		{
			public DateTime? ShippedDate { get; set; }
			public int       OrderID     { get; set; }
			public decimal?  Subtotal    { get; set; }
			public string?   Year        { get; set; }
		}

		#endregion

		#region SalesByCategory

		public static List<SalesByCategoryResult> SalesByCategory(this NorthwindDB dataConnection, string? @CategoryName, string? @OrdYear)
		{
			var parameters = new []
			{
				new DataParameter("@CategoryName", @CategoryName, LinqToDB.DataType.NVarChar)
				{
					Size = 15
				},
				new DataParameter("@OrdYear",      @OrdYear,      LinqToDB.DataType.NVarChar)
				{
					Size = 4
				}
			};

			return dataConnection.QueryProc<SalesByCategoryResult>("[SalesByCategory]", parameters).ToList();
		}

		public partial class SalesByCategoryResult
		{
			public string   ProductName   { get; set; } = null!;
			public decimal? TotalPurchase { get; set; }
		}

		#endregion

		#region TenMostExpensiveProducts

		public static List<TenMostExpensiveProductsResult> TenMostExpensiveProducts(this NorthwindDB dataConnection)
		{
			return dataConnection.QueryProc<TenMostExpensiveProductsResult>("[Ten Most Expensive Products]").ToList();
		}

		public partial class TenMostExpensiveProductsResult
		{
			public string   TenMostExpensiveProducts { get; set; } = null!;
			public decimal? UnitPrice                { get; set; }
		}

		#endregion
	}

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

		public static Customer? Find(this ITable<Customer> table, string CustomerID)
		{
			return table.FirstOrDefault(t =>
				t.CustomerID == CustomerID);
		}

		public static CustomerCustomerDemo? Find(this ITable<CustomerCustomerDemo> table, string CustomerID, string CustomerTypeID)
		{
			return table.FirstOrDefault(t =>
				t.CustomerID     == CustomerID &&
				t.CustomerTypeID == CustomerTypeID);
		}

		public static CustomerDemographic? Find(this ITable<CustomerDemographic> table, string CustomerTypeID)
		{
			return table.FirstOrDefault(t =>
				t.CustomerTypeID == CustomerTypeID);
		}

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

		public static EmployeeTerritory? Find(this ITable<EmployeeTerritory> table, int EmployeeID, string TerritoryID)
		{
			return table.FirstOrDefault(t =>
				t.EmployeeID  == EmployeeID &&
				t.TerritoryID == TerritoryID);
		}

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

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

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

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

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

		public static Territory? Find(this ITable<Territory> table, string TerritoryID)
		{
			return table.FirstOrDefault(t =>
				t.TerritoryID == TerritoryID);
		}

		#region Associations

		#region Customer Associations

		/// <summary>
		/// FK_CustomerCustomerDemo_Customers_BackReference
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public static IQueryable<CustomerCustomerDemo> CustomerCustomerDemoes(this Customer obj, IDataContext db)
		{
			return db.GetTable<CustomerCustomerDemo>().Where(c => c.CustomerID == obj.CustomerID);
		}

		/// <summary>
		/// FK_Orders_Customers_BackReference
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public static IQueryable<Order> Orders(this Customer obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.CustomerID == obj.CustomerID);
		}

		#endregion

		#region CustomerCustomerDemo Associations

		/// <summary>
		/// FK_CustomerCustomerDemo_Customers
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=false)]
		public static IQueryable<Customer> Customers(this CustomerCustomerDemo obj, IDataContext db)
		{
			return db.GetTable<Customer>().Where(c => c.CustomerID == obj.CustomerID);
		}

		/// <summary>
		/// FK_CustomerCustomerDemo_Customers
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=false)]
		public static CustomerCustomerDemo Customer(this Customer obj, IDataContext db)
		{
			return db.GetTable<CustomerCustomerDemo>().Where(c => c.CustomerID == obj.CustomerID).First();
		}

		/// <summary>
		/// FK_CustomerCustomerDemo
		/// </summary>
		[Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID", CanBeNull=false)]
		public static IQueryable<CustomerDemographic> CustomerTypes(this CustomerCustomerDemo obj, IDataContext db)
		{
			return db.GetTable<CustomerDemographic>().Where(c => c.CustomerTypeID == obj.CustomerTypeID);
		}

		/// <summary>
		/// FK_CustomerCustomerDemo
		/// </summary>
		[Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID", CanBeNull=false)]
		public static CustomerCustomerDemo CustomerType(this CustomerDemographic obj, IDataContext db)
		{
			return db.GetTable<CustomerCustomerDemo>().Where(c => c.CustomerTypeID == obj.CustomerTypeID).First();
		}

		#endregion

		#region CustomerDemographic Associations

		/// <summary>
		/// FK_CustomerCustomerDemo_BackReference
		/// </summary>
		[Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID", CanBeNull=true)]
		public static IQueryable<CustomerCustomerDemo> CustomerCustomerDemoes0(this CustomerDemographic obj, IDataContext db)
		{
			return db.GetTable<CustomerCustomerDemo>().Where(c => c.CustomerTypeID == obj.CustomerTypeID);
		}

		#endregion

		#region Employee Associations

		/// <summary>
		/// FK_EmployeeTerritories_Employees_BackReference
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public static IQueryable<EmployeeTerritory> EmployeeTerritories(this Employee obj, IDataContext db)
		{
			return db.GetTable<EmployeeTerritory>().Where(c => c.EmployeeID == obj.EmployeeID);
		}

		/// <summary>
		/// FK_Employees_Employees
		/// </summary>
		[Association(ThisKey="ReportsTo", OtherKey="EmployeeID", CanBeNull=true)]
		public static IQueryable<Employee> FkEmployeesEmployees(this Employee obj, IDataContext db)
		{
			return db.GetTable<Employee>().Where(c => c.EmployeeID == obj.ReportsTo);
		}

		/// <summary>
		/// FK_Employees_Employees
		/// </summary>
		[Association(ThisKey="ReportsTo", OtherKey="EmployeeID", CanBeNull=true)]
		public static Employee? FkEmployeesEmployee(this Employee obj, IDataContext db)
		{
			return db.GetTable<Employee>().Where(c => c.ReportsTo == obj.EmployeeID).FirstOrDefault();
		}

		/// <summary>
		/// FK_Employees_Employees_BackReference
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="ReportsTo", CanBeNull=true)]
		public static IQueryable<Employee> FkEmployeesEmployeesBackReferences(this Employee obj, IDataContext db)
		{
			return db.GetTable<Employee>().Where(c => c.ReportsTo == obj.EmployeeID);
		}

		/// <summary>
		/// FK_Orders_Employees_BackReference
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public static IQueryable<Order> Orders0(this Employee obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.EmployeeID == obj.EmployeeID);
		}

		#endregion

		#region EmployeeTerritory Associations

		/// <summary>
		/// FK_EmployeeTerritories_Employees
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=false)]
		public static IQueryable<Employee> Employees(this EmployeeTerritory obj, IDataContext db)
		{
			return db.GetTable<Employee>().Where(c => c.EmployeeID == obj.EmployeeID);
		}

		/// <summary>
		/// FK_EmployeeTerritories_Employees
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=false)]
		public static EmployeeTerritory Employee(this Employee obj, IDataContext db)
		{
			return db.GetTable<EmployeeTerritory>().Where(c => c.EmployeeID == obj.EmployeeID).First();
		}

		/// <summary>
		/// FK_EmployeeTerritories_Territories
		/// </summary>
		[Association(ThisKey="TerritoryID", OtherKey="TerritoryID", CanBeNull=false)]
		public static IQueryable<Territory> Territories(this EmployeeTerritory obj, IDataContext db)
		{
			return db.GetTable<Territory>().Where(c => c.TerritoryID == obj.TerritoryID);
		}

		/// <summary>
		/// FK_EmployeeTerritories_Territories
		/// </summary>
		[Association(ThisKey="TerritoryID", OtherKey="TerritoryID", CanBeNull=false)]
		public static EmployeeTerritory Territory(this Territory obj, IDataContext db)
		{
			return db.GetTable<EmployeeTerritory>().Where(c => c.TerritoryID == obj.TerritoryID).First();
		}

		#endregion

		#region Order Associations

		/// <summary>
		/// FK_Orders_Customers
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public static IQueryable<Customer> Customers0(this Order obj, IDataContext db)
		{
			return db.GetTable<Customer>().Where(c => c.CustomerID == obj.CustomerID);
		}

		/// <summary>
		/// FK_Orders_Customers
		/// </summary>
		[Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=true)]
		public static Order? Customer0(this Customer obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.CustomerID == obj.CustomerID).FirstOrDefault();
		}

		/// <summary>
		/// FK_Orders_Employees
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public static IQueryable<Employee> Employees0(this Order obj, IDataContext db)
		{
			return db.GetTable<Employee>().Where(c => c.EmployeeID == obj.EmployeeID);
		}

		/// <summary>
		/// FK_Orders_Employees
		/// </summary>
		[Association(ThisKey="EmployeeID", OtherKey="EmployeeID", CanBeNull=true)]
		public static Order? Employee0(this Employee obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.EmployeeID == obj.EmployeeID).FirstOrDefault();
		}

		/// <summary>
		/// FK_Order_Details_Orders_BackReference
		/// </summary>
		[Association(ThisKey="OrderID", OtherKey="ID", CanBeNull=true)]
		public static IQueryable<OrderDetail> OrderDetails(this Order obj, IDataContext db)
		{
			return db.GetTable<OrderDetail>().Where(c => c.ID == obj.OrderID);
		}

		/// <summary>
		/// FK_Orders_Shippers
		/// </summary>
		[Association(ThisKey="ShipVia", OtherKey="ShipperID", CanBeNull=true)]
		public static IQueryable<Shipper> Shippers(this Order obj, IDataContext db)
		{
			return db.GetTable<Shipper>().Where(c => c.ShipperID == obj.ShipVia);
		}

		/// <summary>
		/// FK_Orders_Shippers
		/// </summary>
		[Association(ThisKey="ShipVia", OtherKey="ShipperID", CanBeNull=true)]
		public static Order? Shipper(this Shipper obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.ShipVia == obj.ShipperID).FirstOrDefault();
		}

		#endregion

		#region OrderDetail Associations

		/// <summary>
		/// FK_Order_Details_Orders
		/// </summary>
		[Association(ThisKey="ID", OtherKey="OrderID", CanBeNull=false)]
		public static IQueryable<Order> Orders1(this OrderDetail obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.OrderID == obj.ID);
		}

		/// <summary>
		/// FK_Order_Details_Orders
		/// </summary>
		[Association(ThisKey="ID", OtherKey="OrderID", CanBeNull=false)]
		public static OrderDetail Order(this Order obj, IDataContext db)
		{
			return db.GetTable<OrderDetail>().Where(c => c.ID == obj.OrderID).First();
		}

		#endregion

		#region Region Associations

		/// <summary>
		/// FK_Territories_Region_BackReference
		/// </summary>
		[Association(ThisKey="RegionID", OtherKey="RegionID", CanBeNull=true)]
		public static IQueryable<Territory> Territories0(this Region obj, IDataContext db)
		{
			return db.GetTable<Territory>().Where(c => c.RegionID == obj.RegionID);
		}

		#endregion

		#region Shipper Associations

		/// <summary>
		/// FK_Orders_Shippers_BackReference
		/// </summary>
		[Association(ThisKey="ShipperID", OtherKey="ShipVia", CanBeNull=true)]
		public static IQueryable<Order> Orders2(this Shipper obj, IDataContext db)
		{
			return db.GetTable<Order>().Where(c => c.ShipVia == obj.ShipperID);
		}

		#endregion

		#region Territory Associations

		/// <summary>
		/// FK_EmployeeTerritories_Territories_BackReference
		/// </summary>
		[Association(ThisKey="TerritoryID", OtherKey="TerritoryID", CanBeNull=true)]
		public static IQueryable<EmployeeTerritory> EmployeeTerritories0(this Territory obj, IDataContext db)
		{
			return db.GetTable<EmployeeTerritory>().Where(c => c.TerritoryID == obj.TerritoryID);
		}

		/// <summary>
		/// FK_Territories_Region
		/// </summary>
		[Association(ThisKey="RegionID", OtherKey="RegionID", CanBeNull=false)]
		public static IQueryable<Region> Regions(this Territory obj, IDataContext db)
		{
			return db.GetTable<Region>().Where(c => c.RegionID == obj.RegionID);
		}

		/// <summary>
		/// FK_Territories_Region
		/// </summary>
		[Association(ThisKey="RegionID", OtherKey="RegionID", CanBeNull=false)]
		public static Territory Region(this Region obj, IDataContext db)
		{
			return db.GetTable<Territory>().Where(c => c.RegionID == obj.RegionID).First();
		}

		#endregion

		#endregion
	}

	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<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<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>(); } }
		/// <summary>
		/// This is Parent table
		/// </summary>
		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<Provider>                Providers                { get { return this.GetTable<Provider>(); } }
		public ITable<SameTableName>           SameTableNames           { get { return this.GetTable<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<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>(); } }

		#region Schemas

		public MySchemaSchema.DataContext MySchema { get; set; } = null!;

		public void InitSchemas()
		{
			MySchema = new MySchemaSchema.DataContext(this);
		}

		#endregion

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

		public TestDataDB(string configuration)
			: base(configuration)
		{
			InitSchemas();
			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(Name="GetParentByID")]
		public ITable<Parent> GetParentByID(int? @id)
		{
			return this.GetTable<Parent>(this, (MethodInfo)MethodBase.GetCurrentMethod()!,
				@id);
		}

		#endregion

		#region Issue1921

		[Sql.TableFunction(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("AllTypes")]
	public partial class AllType
	{
		[Column(                            DbType="int",               DataType=LinqToDB.DataType.Int32),                                                PrimaryKey, Identity] public int             ID                       { get; set; } // int
		[Column("bigintDataType",           DbType="bigint",            DataType=LinqToDB.DataType.Int64),                                                Nullable            ] public long?           BigintDataType           { get; set; } // bigint
		[Column("numericDataType",          DbType="numeric(18, 1)",    DataType=LinqToDB.DataType.Decimal,        Precision=18, Scale=1),                Nullable            ] public decimal?        NumericDataType          { get; set; } // numeric(18, 1)
		[Column("bitDataType",              DbType="bit",               DataType=LinqToDB.DataType.Boolean),                                              Nullable            ] public bool?           BitDataType              { get; set; } // bit
		[Column("smallintDataType",         DbType="smallint",          DataType=LinqToDB.DataType.Int16),                                                Nullable            ] public short?          SmallintDataType         { get; set; } // smallint
		[Column("decimalDataType",          DbType="decimal(18, 1)",    DataType=LinqToDB.DataType.Decimal,        Precision=18, Scale=1),                Nullable            ] public decimal?        DecimalDataType          { get; set; } // decimal(18, 1)
		[Column("smallmoneyDataType",       DbType="smallmoney",        DataType=LinqToDB.DataType.SmallMoney),                                           Nullable            ] public decimal?        SmallmoneyDataType       { get; set; } // smallmoney
		[Column("intDataType",              DbType="int",               DataType=LinqToDB.DataType.Int32),                                                Nullable            ] public int?            IntDataType              { get; set; } // int
		[Column("tinyintDataType",          DbType="tinyint",           DataType=LinqToDB.DataType.Byte),                                                 Nullable            ] public byte?           TinyintDataType          { get; set; } // tinyint
		[Column("moneyDataType",            DbType="money",             DataType=LinqToDB.DataType.Money),                                                Nullable            ] public decimal?        MoneyDataType            { get; set; } // money
		[Column("floatDataType",            DbType="float",             DataType=LinqToDB.DataType.Double),                                               Nullable            ] public double?         FloatDataType            { get; set; } // float
		[Column("realDataType",             DbType="real",              DataType=LinqToDB.DataType.Single),                                               Nullable            ] public float?          RealDataType             { get; set; } // real
		[Column("datetimeDataType",         DbType="datetime",          DataType=LinqToDB.DataType.DateTime),                                             Nullable            ] public DateTime?       DatetimeDataType         { get; set; } // datetime
		[Column("smalldatetimeDataType",    DbType="smalldatetime",     DataType=LinqToDB.DataType.SmallDateTime),                                        Nullable            ] public DateTime?       SmalldatetimeDataType    { get; set; } // smalldatetime
		[Column("charDataType",             DbType="char(1)",           DataType=LinqToDB.DataType.Char,           Length=1),                             Nullable            ] public char?           CharDataType             { get; set; } // char(1)
		[Column("char20DataType",           DbType="char(20)",          DataType=LinqToDB.DataType.Char,           Length=20),                            Nullable            ] public string?         Char20DataType           { get; set; } // char(20)
		[Column("varcharDataType",          DbType="varchar(20)",       DataType=LinqToDB.DataType.VarChar,        Length=20),                            Nullable            ] public string?         VarcharDataType          { get; set; } // varchar(20)
		[Column("textDataType",             DbType="text",              DataType=LinqToDB.DataType.Text),                                                 Nullable            ] public string?         TextDataType             { get; set; } // text
		[Column("ncharDataType",            DbType="nchar(20)",         DataType=LinqToDB.DataType.NChar,          Length=20),                            Nullable            ] public string?         NcharDataType            { get; set; } // nchar(20)
		[Column("nvarcharDataType",         DbType="nvarchar(20)",      DataType=LinqToDB.DataType.NVarChar,       Length=20),                            Nullable            ] public string?         NvarcharDataType         { get; set; } // nvarchar(20)
		[Column("ntextDataType",            DbType="ntext",             DataType=LinqToDB.DataType.NText),                                                Nullable            ] public string?         NtextDataType            { get; set; } // ntext
		[Column("binaryDataType",           DbType="binary(1)",         DataType=LinqToDB.DataType.Binary,         Length=1),                             Nullable            ] public byte[]?         BinaryDataType           { get; set; } // binary(1)
		[Column("varbinaryDataType",        DbType="varbinary(1)",      DataType=LinqToDB.DataType.VarBinary,      Length=1),                             Nullable            ] public byte[]?         VarbinaryDataType        { get; set; } // varbinary(1)
		[Column("imageDataType",            DbType="image",             DataType=LinqToDB.DataType.Image),                                                Nullable            ] public byte[]?         ImageDataType            { get; set; } // image
		[Column("timestampDataType",        DbType="timestamp",         DataType=LinqToDB.DataType.Timestamp,      SkipOnInsert=true, SkipOnUpdate=true), Nullable            ] public byte[]?         TimestampDataType        { get; set; } // timestamp
		[Column("uniqueidentifierDataType", DbType="uniqueidentifier",  DataType=LinqToDB.DataType.Guid),                                                 Nullable            ] public Guid?           UniqueidentifierDataType { get; set; } // uniqueidentifier
		[Column("sql_variantDataType",      DbType="sql_variant",       DataType=LinqToDB.DataType.Variant),                                              Nullable            ] public object?         SqlVariantDataType       { get; set; } // sql_variant
		[Column("nvarchar_max_DataType",    DbType="nvarchar(max)",     DataType=LinqToDB.DataType.NVarChar,       Length=int.MaxValue),                  Nullable            ] public string?         NvarcharMaxDataType      { get; set; } // nvarchar(max)
		[Column("varchar_max_DataType",     DbType="varchar(max)",      DataType=LinqToDB.DataType.VarChar,        Length=int.MaxValue),                  Nullable            ] public string?         VarcharMaxDataType       { get; set; } // varchar(max)
		[Column("varbinary_max_DataType",   DbType="varbinary(max)",    DataType=LinqToDB.DataType.VarBinary,      Length=int.MaxValue),                  Nullable            ] public byte[]?         VarbinaryMaxDataType     { get; set; } // varbinary(max)
		[Column("xmlDataType",              DbType="xml",               DataType=LinqToDB.DataType.Xml),                                                  Nullable            ] public string?         XmlDataType              { get; set; } // xml
		[Column("datetime2DataType",        DbType="datetime2(7)",      DataType=LinqToDB.DataType.DateTime2,      Precision=7),                          Nullable            ] public DateTime?       Datetime2DataType        { get; set; } // datetime2(7)
		[Column("datetimeoffsetDataType",   DbType="datetimeoffset(7)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=7),                          Nullable            ] public DateTimeOffset? DatetimeoffsetDataType   { get; set; } // datetimeoffset(7)
		[Column("datetimeoffset0DataType",  DbType="datetimeoffset(0)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=0),                          Nullable            ] public DateTimeOffset? Datetimeoffset0DataType  { get; set; } // datetimeoffset(0)
		[Column("datetimeoffset1DataType",  DbType="datetimeoffset(1)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=1),                          Nullable            ] public DateTimeOffset? Datetimeoffset1DataType  { get; set; } // datetimeoffset(1)
		[Column("datetimeoffset2DataType",  DbType="datetimeoffset(2)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=2),                          Nullable            ] public DateTimeOffset? Datetimeoffset2DataType  { get; set; } // datetimeoffset(2)
		[Column("datetimeoffset3DataType",  DbType="datetimeoffset(3)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=3),                          Nullable            ] public DateTimeOffset? Datetimeoffset3DataType  { get; set; } // datetimeoffset(3)
		[Column("datetimeoffset4DataType",  DbType="datetimeoffset(4)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=4),                          Nullable            ] public DateTimeOffset? Datetimeoffset4DataType  { get; set; } // datetimeoffset(4)
		[Column("datetimeoffset5DataType",  DbType="datetimeoffset(5)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=5),                          Nullable            ] public DateTimeOffset? Datetimeoffset5DataType  { get; set; } // datetimeoffset(5)
		[Column("datetimeoffset6DataType",  DbType="datetimeoffset(6)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=6),                          Nullable            ] public DateTimeOffset? Datetimeoffset6DataType  { get; set; } // datetimeoffset(6)
		[Column("datetimeoffset7DataType",  DbType="datetimeoffset(7)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=7),                          Nullable            ] public DateTimeOffset? Datetimeoffset7DataType  { get; set; } // datetimeoffset(7)
		[Column("dateDataType",             DbType="date",              DataType=LinqToDB.DataType.Date),                                                 Nullable            ] public DateTime?       DateDataType             { get; set; } // date
		[Column("timeDataType",             DbType="time(7)",           DataType=LinqToDB.DataType.Time,           Precision=7),                          Nullable            ] public TimeSpan?       TimeDataType             { get; set; } // time(7)
	}

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

	[Table("Child")]
	public partial class Child
	{
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? ParentID { get; set; } // int
		/// <summary>
		/// This ChildID column
		/// </summary>
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? ChildID  { get; set; } // int
		[Column("_ID", DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, Identity] public int  Id       { get; set; } // int
	}

	[Table("CollatedTable")]
	public partial class CollatedTable
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               NotNull] public int    Id              { get; set; } // int
		[Column(DbType="nvarchar(20)", DataType=LinqToDB.DataType.NVarChar, Length=20), NotNull] public string CaseSensitive   { get; set; } = null!; // nvarchar(20)
		[Column(DbType="nvarchar(20)", DataType=LinqToDB.DataType.NVarChar, Length=20), NotNull] public string CaseInsensitive { get; set; } = null!; // nvarchar(20)
	}

	[Table("DataType")]
	public partial class DataType
	{
		[Column("id", DbType="int", DataType=LinqToDB.DataType.Int32), NotNull] public int Id { get; set; } // int
	}

	[Table("DecimalOverflow")]
	public partial class DecimalOverflow
	{
		[Column(DbType="decimal(38, 20)", DataType=LinqToDB.DataType.Decimal, Precision=38, Scale=20), PrimaryKey,  NotNull] public decimal  Decimal1 { get; set; } // decimal(38, 20)
		[Column(DbType="decimal(31, 2)",  DataType=LinqToDB.DataType.Decimal, Precision=31, Scale=2),     Nullable         ] public decimal? Decimal2 { get; set; } // decimal(31, 2)
		[Column(DbType="decimal(38, 36)", DataType=LinqToDB.DataType.Decimal, Precision=38, Scale=36),    Nullable         ] public decimal? Decimal3 { get; set; } // decimal(38, 36)
		[Column(DbType="decimal(29, 0)",  DataType=LinqToDB.DataType.Decimal, Precision=29, Scale=0),     Nullable         ] public decimal? Decimal4 { get; set; } // decimal(29, 0)
		[Column(DbType="decimal(38, 38)", DataType=LinqToDB.DataType.Decimal, Precision=38, Scale=38),    Nullable         ] public decimal? Decimal5 { get; set; } // decimal(38, 38)
	}

	[Table("Doctor")]
	public partial class Doctor
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey, NotNull] public int    PersonID { get; set; } // int
		[Column(DbType="nvarchar(50)", DataType=LinqToDB.DataType.NVarChar, Length=50),             NotNull] public string Taxonomy { get; set; } = null!; // nvarchar(50)
	}

	[Table("GrandChild")]
	public partial class GrandChild
	{
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? ParentID     { get; set; } // int
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? ChildID      { get; set; } // int
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? GrandChildID { get; set; } // int
		[Column("_ID", DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, Identity] public int  Id           { get; set; } // int
	}

	[Table("GuidID")]
	public partial class GuidID
	{
		[Column(DbType="uniqueidentifier", DataType=LinqToDB.DataType.Guid),  PrimaryKey,  NotNull] public Guid ID     { get; set; } // uniqueidentifier
		[Column(DbType="int",              DataType=LinqToDB.DataType.Int32),    Nullable         ] public int? Field1 { get; set; } // int
	}

	[Table("GuidID2")]
	public partial class GuidID2
	{
		[Column(DbType="uniqueidentifier", DataType=LinqToDB.DataType.Guid), PrimaryKey, NotNull] public Guid ID { get; set; } // uniqueidentifier
	}

	[Table("IndexTable")]
	public partial class IndexTable
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey(2), NotNull] public int PKField1    { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey(1), NotNull] public int PKField2    { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32),                NotNull] public int UniqueField { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32),                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("IndexTable2")]
	public partial class IndexTable2
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey(2), NotNull] public int PKField1 { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), 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("InheritanceChild")]
	public partial class InheritanceChild
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey,  NotNull] public int     InheritanceChildId  { get; set; } // int
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                            NotNull] public int     InheritanceParentId { get; set; } // int
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                  Nullable         ] public int?    TypeDiscriminator   { get; set; } // int
		[Column(DbType="nvarchar(50)", DataType=LinqToDB.DataType.NVarChar, Length=50),    Nullable         ] public string? Name                { get; set; } // nvarchar(50)
	}

	[Table("InheritanceParent")]
	public partial class InheritanceParent
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey,  NotNull] public int     InheritanceParentId { get; set; } // int
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),                  Nullable         ] public int?    TypeDiscriminator   { get; set; } // int
		[Column(DbType="nvarchar(50)", DataType=LinqToDB.DataType.NVarChar, Length=50),    Nullable         ] public string? Name                { get; set; } // nvarchar(50)
	}

	[Table("Issue1115")]
	public partial class Issue1115
	{
		[Column("id", DbType="hierarchyid", DataType=LinqToDB.DataType.Udt), PrimaryKey, NotNull] public SqlHierarchyId Id { get; set; } // hierarchyid
	}

	[Table("Issue1144")]
	public partial class Issue1144
	{
		/// <summary>
		/// Column description
		/// </summary>
		[Column("id", DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, NotNull] public int Id { get; set; } // int
	}

	[Table("LinqDataTypes")]
	public partial class LinqDataType
	{
		[Column("_ID", DbType="int",              DataType=LinqToDB.DataType.Int32),                            PrimaryKey, Identity] public int       Id             { get; set; } // int
		[Column(       DbType="int",              DataType=LinqToDB.DataType.Int32),                            Nullable            ] public int?      ID             { get; set; } // int
		[Column(       DbType="decimal(10, 4)",   DataType=LinqToDB.DataType.Decimal,   Precision=10, Scale=4), Nullable            ] public decimal?  MoneyValue     { get; set; } // decimal(10, 4)
		[Column(       DbType="datetime",         DataType=LinqToDB.DataType.DateTime),                         Nullable            ] public DateTime? DateTimeValue  { get; set; } // datetime
		[Column(       DbType="datetime2(7)",     DataType=LinqToDB.DataType.DateTime2, Precision=7),           Nullable            ] public DateTime? DateTimeValue2 { get; set; } // datetime2(7)
		[Column(       DbType="bit",              DataType=LinqToDB.DataType.Boolean),                          Nullable            ] public bool?     BoolValue      { get; set; } // bit
		[Column(       DbType="uniqueidentifier", DataType=LinqToDB.DataType.Guid),                             Nullable            ] public Guid?     GuidValue      { get; set; } // uniqueidentifier
		[Column(       DbType="varbinary(5000)",  DataType=LinqToDB.DataType.VarBinary, Length=5000),           Nullable            ] public byte[]?   BinaryValue    { get; set; } // varbinary(5000)
		[Column(       DbType="smallint",         DataType=LinqToDB.DataType.Int16),                            Nullable            ] public short?    SmallIntValue  { get; set; } // smallint
		[Column(       DbType="int",              DataType=LinqToDB.DataType.Int32),                            Nullable            ] public int?      IntValue       { get; set; } // int
		[Column(       DbType="bigint",           DataType=LinqToDB.DataType.Int64),                            Nullable            ] public long?     BigIntValue    { get; set; } // bigint
		[Column(       DbType="nvarchar(50)",     DataType=LinqToDB.DataType.NVarChar,  Length=50),             Nullable            ] public string?   StringValue    { get; set; } // nvarchar(50)
	}

	[Table("Member")]
	public partial class Member
	{
		[Column(DbType="int",          DataType=LinqToDB.DataType.Int32),               PrimaryKey, Identity] public int    MemberId { get; set; } // int
		[Column(DbType="nvarchar(50)", DataType=LinqToDB.DataType.NVarChar, Length=50), 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("Name.Test")]
	public partial class NameTest
	{
		[Column("Name.Test", DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? NameTestColumn { get; set; } // int
	}

	/// <summary>
	/// This is Parent table
	/// </summary>
	[Table("Parent")]
	public partial class Parent
	{
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? ParentID { get; set; } // int
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? Value1   { get; set; } // int
		[Column("_ID", DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, Identity] public int  Id       { get; set; } // int
	}

	[Table("ParentChildView", IsView=true)]
	public partial class ParentChildView
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? ParentID { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? Value1   { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? ChildID  { get; set; } // int
	}

	[Table("ParentView", IsView=true)]
	public partial class ParentView
	{
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? ParentID { get; set; } // int
		[Column(       DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? Value1   { get; set; } // int
		[Column("_ID", DbType="int", DataType=LinqToDB.DataType.Int32), Identity] public int  Id       { get; set; } // int
	}

	[Table("Patient")]
	public partial class Patient
	{
		[Column(DbType="int",           DataType=LinqToDB.DataType.Int32),                PrimaryKey, NotNull] public int    PersonID  { get; set; } // int
		[Column(DbType="nvarchar(256)", DataType=LinqToDB.DataType.NVarChar, Length=256),             NotNull] public string Diagnosis { get; set; } = null!; // nvarchar(256)
	}

	[Table("Provider")]
	public partial class Provider
	{
		[Column(DbType="int",           DataType=LinqToDB.DataType.Int32),                         PrimaryKey, NotNull] public int    ProviderId { get; set; } // int
		[Column(DbType="nvarchar(max)", DataType=LinqToDB.DataType.NVarChar, Length=int.MaxValue),             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("SameTableName")]
	public partial class SameTableName
	{
		[Column("id", DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? Id { get; set; } // int
	}

	[Table("SqlTypes")]
	public partial class SqlType
	{
		[Column(DbType="int",         DataType=LinqToDB.DataType.Int32), PrimaryKey,  NotNull] public int             ID  { get; set; } // int
		[Column(DbType="hierarchyid", DataType=LinqToDB.DataType.Udt),      Nullable         ] public SqlHierarchyId? HID { get; set; } // hierarchyid
	}

	[Table("TestIdentity")]
	public partial class TestIdentity
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, Identity] public int ID { get; set; } // int
	}

	[Table("TestMerge1")]
	public partial class TestMerge1
	{
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                  PrimaryKey,  NotNull] public int             Id              { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field1          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field2          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field3          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field4          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field5          { get; set; } // int
		[Column(DbType="bigint",            DataType=LinqToDB.DataType.Int64),                                     Nullable         ] public long?           FieldInt64      { get; set; } // bigint
		[Column(DbType="bit",               DataType=LinqToDB.DataType.Boolean),                                   Nullable         ] public bool?           FieldBoolean    { get; set; } // bit
		[Column(DbType="varchar(20)",       DataType=LinqToDB.DataType.VarChar,        Length=20),                 Nullable         ] public string?         FieldString     { get; set; } // varchar(20)
		[Column(DbType="nvarchar(20)",      DataType=LinqToDB.DataType.NVarChar,       Length=20),                 Nullable         ] public string?         FieldNString    { get; set; } // nvarchar(20)
		[Column(DbType="char(1)",           DataType=LinqToDB.DataType.Char,           Length=1),                  Nullable         ] public char?           FieldChar       { get; set; } // char(1)
		[Column(DbType="nchar(1)",          DataType=LinqToDB.DataType.NChar,          Length=1),                  Nullable         ] public char?           FieldNChar      { get; set; } // nchar(1)
		[Column(DbType="real",              DataType=LinqToDB.DataType.Single),                                    Nullable         ] public float?          FieldFloat      { get; set; } // real
		[Column(DbType="float",             DataType=LinqToDB.DataType.Double),                                    Nullable         ] public double?         FieldDouble     { get; set; } // float
		[Column(DbType="datetime",          DataType=LinqToDB.DataType.DateTime),                                  Nullable         ] public DateTime?       FieldDateTime   { get; set; } // datetime
		[Column(DbType="datetimeoffset(7)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=7),               Nullable         ] public DateTimeOffset? FieldDateTime2  { get; set; } // datetimeoffset(7)
		[Column(DbType="varbinary(20)",     DataType=LinqToDB.DataType.VarBinary,      Length=20),                 Nullable         ] public byte[]?         FieldBinary     { get; set; } // varbinary(20)
		[Column(DbType="uniqueidentifier",  DataType=LinqToDB.DataType.Guid),                                      Nullable         ] public Guid?           FieldGuid       { get; set; } // uniqueidentifier
		[Column(DbType="decimal(24, 10)",   DataType=LinqToDB.DataType.Decimal,        Precision=24, Scale=10),    Nullable         ] public decimal?        FieldDecimal    { get; set; } // decimal(24, 10)
		[Column(DbType="date",              DataType=LinqToDB.DataType.Date),                                      Nullable         ] public DateTime?       FieldDate       { get; set; } // date
		[Column(DbType="time(7)",           DataType=LinqToDB.DataType.Time,           Precision=7),               Nullable         ] public TimeSpan?       FieldTime       { get; set; } // time(7)
		[Column(DbType="varchar(20)",       DataType=LinqToDB.DataType.VarChar,        Length=20),                 Nullable         ] public string?         FieldEnumString { get; set; } // varchar(20)
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            FieldEnumNumber { get; set; } // int
	}

	[Table("TestMerge2")]
	public partial class TestMerge2
	{
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                  PrimaryKey,  NotNull] public int             Id              { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field1          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field2          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field3          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field4          { get; set; } // int
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            Field5          { get; set; } // int
		[Column(DbType="bigint",            DataType=LinqToDB.DataType.Int64),                                     Nullable         ] public long?           FieldInt64      { get; set; } // bigint
		[Column(DbType="bit",               DataType=LinqToDB.DataType.Boolean),                                   Nullable         ] public bool?           FieldBoolean    { get; set; } // bit
		[Column(DbType="varchar(20)",       DataType=LinqToDB.DataType.VarChar,        Length=20),                 Nullable         ] public string?         FieldString     { get; set; } // varchar(20)
		[Column(DbType="nvarchar(20)",      DataType=LinqToDB.DataType.NVarChar,       Length=20),                 Nullable         ] public string?         FieldNString    { get; set; } // nvarchar(20)
		[Column(DbType="char(1)",           DataType=LinqToDB.DataType.Char,           Length=1),                  Nullable         ] public char?           FieldChar       { get; set; } // char(1)
		[Column(DbType="nchar(1)",          DataType=LinqToDB.DataType.NChar,          Length=1),                  Nullable         ] public char?           FieldNChar      { get; set; } // nchar(1)
		[Column(DbType="real",              DataType=LinqToDB.DataType.Single),                                    Nullable         ] public float?          FieldFloat      { get; set; } // real
		[Column(DbType="float",             DataType=LinqToDB.DataType.Double),                                    Nullable         ] public double?         FieldDouble     { get; set; } // float
		[Column(DbType="datetime",          DataType=LinqToDB.DataType.DateTime),                                  Nullable         ] public DateTime?       FieldDateTime   { get; set; } // datetime
		[Column(DbType="datetimeoffset(7)", DataType=LinqToDB.DataType.DateTimeOffset, Precision=7),               Nullable         ] public DateTimeOffset? FieldDateTime2  { get; set; } // datetimeoffset(7)
		[Column(DbType="varbinary(20)",     DataType=LinqToDB.DataType.VarBinary,      Length=20),                 Nullable         ] public byte[]?         FieldBinary     { get; set; } // varbinary(20)
		[Column(DbType="uniqueidentifier",  DataType=LinqToDB.DataType.Guid),                                      Nullable         ] public Guid?           FieldGuid       { get; set; } // uniqueidentifier
		[Column(DbType="decimal(24, 10)",   DataType=LinqToDB.DataType.Decimal,        Precision=24, Scale=10),    Nullable         ] public decimal?        FieldDecimal    { get; set; } // decimal(24, 10)
		[Column(DbType="date",              DataType=LinqToDB.DataType.Date),                                      Nullable         ] public DateTime?       FieldDate       { get; set; } // date
		[Column(DbType="time(7)",           DataType=LinqToDB.DataType.Time,           Precision=7),               Nullable         ] public TimeSpan?       FieldTime       { get; set; } // time(7)
		[Column(DbType="varchar(20)",       DataType=LinqToDB.DataType.VarChar,        Length=20),                 Nullable         ] public string?         FieldEnumString { get; set; } // varchar(20)
		[Column(DbType="int",               DataType=LinqToDB.DataType.Int32),                                     Nullable         ] public int?            FieldEnumNumber { get; set; } // int
	}

	[Table("TestMergeIdentity")]
	public partial class TestMergeIdentity
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, Identity] public int  Id    { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), Nullable            ] public int? Field { get; set; } // int
	}

	[Table("TestSchema_SameTableName")]
	public partial class TestSchemaSameTableName
	{
		[Column("id", DbType="int", DataType=LinqToDB.DataType.Int32), Nullable] public int? Id { get; set; } // int
	}

	[Table("TestSchemaX")]
	public partial class TestSchemaX
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, NotNull] public int TestSchemaXID { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32),             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 List<TestSchemaY> TestSchemaY { get; set; } = null!;

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

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

		#endregion
	}

	[Table("TestSchemaY")]
	public partial class TestSchemaY
	{
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), NotNull] public int TestSchemaXID       { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), NotNull] public int ParentTestSchemaXID { get; set; } // int
		[Column(DbType="int", DataType=LinqToDB.DataType.Int32), 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("[AddIssue792Record]");
		}

		#endregion

		#region DuplicateColumnNames

		public static List<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),
				},
				"[DuplicateColumnNames]").ToList();
		}

		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("[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 List<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),
				},
				"[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, out int @return)
		{
			var parameters = new []
			{
				new DataParameter("@return", null, LinqToDB.DataType.Int32)
				{
					Direction = ParameterDirection.ReturnValue
				}
			};

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

			@return = Converter.ChangeTypeTo<int>(parameters[0].Value);

			return ret;
		}

		#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("[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("[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 List<PatientSelectAllResult> PatientSelectAll(this TestDataDB dataConnection)
		{
			return dataConnection.QueryProc<PatientSelectAllResult>("[Patient_SelectAll]").ToList();
		}

		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 List<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>("[Patient_SelectByName]", parameters).ToList();
		}

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

		#endregion

		#region PersonInsert

		public static List<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>("[Person_Insert]", parameters).ToList();
		}

		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("[Person_Insert_OutputParameter]", parameters);

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

			return ret;
		}

		#endregion

		#region PersonSelectAll

		public static List<PersonSelectAllResult> PersonSelectAll(this TestDataDB dataConnection)
		{
			return dataConnection.QueryProc<PersonSelectAllResult>("[Person_SelectAll]").ToList();
		}

		public partial class PersonSelectAllResult
		{
			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; }
		}

		#endregion

		#region PersonSelectByKey

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

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

		public partial class PersonSelectByKeyResult
		{
			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; }
		}

		#endregion

		#region PersonSelectByKeyLowercase

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

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

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

		#endregion

		#region PersonSelectByName

		public static List<PersonSelectByNameResult> 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<PersonSelectByNameResult>("[Person_SelectByName]", parameters).ToList();
		}

		public partial class PersonSelectByNameResult
		{
			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; }
		}

		#endregion

		#region PersonSelectListByName

		public static List<PersonSelectListByNameResult> 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<PersonSelectListByNameResult>("[Person_SelectListByName]", parameters).ToList();
		}

		public partial class PersonSelectListByNameResult
		{
			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; }
		}

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

		#endregion

		#region QueryProcMultipleParameters

		public static List<QueryProcMultipleParametersResult> 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<QueryProcMultipleParametersResult>("[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;
		}

		public partial class QueryProcMultipleParametersResult
		{
			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; }
		}

		#endregion

		#region QueryProcParameters

		public static List<QueryProcParametersResult> 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<QueryProcParametersResult>("[QueryProcParameters]", parameters).ToList();

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

			return ret;
		}

		public partial class QueryProcParametersResult
		{
			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; }
		}

		#endregion

		#region SelectImplicitColumn

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

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

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

		#endregion

		#region TableTypeTestProc

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

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

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

		#endregion

		#region VariableResults

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

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

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

		#region Associations

		#region IndexTable Associations

		/// <summary>
		/// FK_Patient2_IndexTable_BackReference
		/// </summary>
		[Association(ThisKey="PKField2, PKField1", OtherKey="PKField2, PKField1", CanBeNull=true)]
		public static IQueryable<IndexTable2> Patients(this IndexTable obj, IDataContext db)
		{
			return db.GetTable<IndexTable2>().Where(c => c.PKField2 == obj.PKField2 && c.PKField1 == obj.PKField1);
		}

		/// <summary>
		/// FK_Patient2_IndexTable_BackReference
		/// </summary>
		[Association(ThisKey="PKField2, PKField1", OtherKey="PKField2, PKField1", CanBeNull=true)]
		public static IndexTable? Patient(this IndexTable2 obj, IDataContext db)
		{
			return db.GetTable<IndexTable>().Where(c => c.PKField2 == obj.PKField2 && c.PKField1 == obj.PKField1).FirstOrDefault();
		}

		#endregion

		#region IndexTable2 Associations

		/// <summary>
		/// FK_Patient2_IndexTable
		/// </summary>
		[Association(ThisKey="PKField2, PKField1", OtherKey="PKField2, PKField1", CanBeNull=false)]
		public static IQueryable<IndexTable> Patient2IndexTables(this IndexTable2 obj, IDataContext db)
		{
			return db.GetTable<IndexTable>().Where(c => c.PKField2 == obj.PKField2 && c.PKField1 == obj.PKField1);
		}

		/// <summary>
		/// FK_Patient2_IndexTable
		/// </summary>
		[Association(ThisKey="PKField2, PKField1", OtherKey="PKField2, PKField1", CanBeNull=false)]
		public static IndexTable2 Patient2IndexTable(this IndexTable obj, IDataContext db)
		{
			return db.GetTable<IndexTable2>().Where(c => c.PKField2 == obj.PKField2 && c.PKField1 == obj.PKField1).First();
		}

		#endregion

		#region Member Associations

		/// <summary>
		/// FK_Provider_Member_BackReference
		/// </summary>
		[Association(ThisKey="MemberId", OtherKey="ProviderId", CanBeNull=true)]
		public static IQueryable<Provider> Providers(this Member obj, IDataContext db)
		{
			return db.GetTable<Provider>().Where(c => c.ProviderId == obj.MemberId);
		}

		/// <summary>
		/// FK_Provider_Member_BackReference
		/// </summary>
		[Association(ThisKey="MemberId", OtherKey="ProviderId", CanBeNull=true)]
		public static Member? Provider(this Provider obj, IDataContext db)
		{
			return db.GetTable<Member>().Where(c => c.MemberId == obj.ProviderId).FirstOrDefault();
		}

		#endregion

		#region Provider Associations

		/// <summary>
		/// FK_Provider_Member
		/// </summary>
		[Association(ThisKey="ProviderId", OtherKey="MemberId", CanBeNull=false)]
		public static IQueryable<Member> Members(this Provider obj, IDataContext db)
		{
			return db.GetTable<Member>().Where(c => c.MemberId == obj.ProviderId);
		}

		/// <summary>
		/// FK_Provider_Member
		/// </summary>
		[Association(ThisKey="ProviderId", OtherKey="MemberId", CanBeNull=false)]
		public static Provider Member(this Member obj, IDataContext db)
		{
			return db.GetTable<Provider>().Where(c => c.ProviderId == obj.MemberId).First();
		}

		#endregion

		#region TestSchemaA Associations

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA2_BackReference
		/// </summary>
		[Association(ThisKey="TestSchemaAID", OtherKey="TargetTestSchemaAId", CanBeNull=true)]
		public static IQueryable<MySchemaSchema.TestSchemaB> FkTestSchemaTestSchemaBYTargetTestSchemaA2BackReferences(this MySchemaSchema.TestSchemaA obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaB>().Where(c => c.TargetTestSchemaAId == obj.TestSchemaAID);
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_OriginTestSchemaA_BackReference
		/// </summary>
		[Association(ThisKey="TestSchemaAID", OtherKey="OriginTestSchemaAID", CanBeNull=true)]
		public static IQueryable<MySchemaSchema.TestSchemaB> TestSchemaBYOriginTestSchemaA(this MySchemaSchema.TestSchemaA obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaB>().Where(c => c.OriginTestSchemaAID == obj.TestSchemaAID);
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA_BackReference
		/// </summary>
		[Association(ThisKey="TestSchemaAID", OtherKey="TargetTestSchemaAID", CanBeNull=true)]
		public static IQueryable<MySchemaSchema.TestSchemaB> TestSchemaBYTargetTestSchemaA(this MySchemaSchema.TestSchemaA obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaB>().Where(c => c.TargetTestSchemaAID == obj.TestSchemaAID);
		}

		#endregion

		#region TestSchemaB Associations

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA
		/// </summary>
		[Association(ThisKey="TargetTestSchemaAID", OtherKey="TestSchemaAID", CanBeNull=false)]
		public static IQueryable<MySchemaSchema.TestSchemaA> FKTargetTestSchemaA(this MySchemaSchema.TestSchemaB obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaA>().Where(c => c.TestSchemaAID == obj.TargetTestSchemaAID);
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA
		/// </summary>
		[Association(ThisKey="TargetTestSchemaAID", OtherKey="TestSchemaAID", CanBeNull=false)]
		public static MySchemaSchema.TestSchemaB FKTargetTestSchemaA0(this MySchemaSchema.TestSchemaA obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaB>().Where(c => c.TargetTestSchemaAID == obj.TestSchemaAID).First();
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_OriginTestSchemaA
		/// </summary>
		[Association(ThisKey="OriginTestSchemaAID", OtherKey="TestSchemaAID", CanBeNull=false)]
		public static IQueryable<MySchemaSchema.TestSchemaA> OriginTestSchemaA(this MySchemaSchema.TestSchemaB obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaA>().Where(c => c.TestSchemaAID == obj.OriginTestSchemaAID);
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_OriginTestSchemaA
		/// </summary>
		[Association(ThisKey="OriginTestSchemaAID", OtherKey="TestSchemaAID", CanBeNull=false)]
		public static MySchemaSchema.TestSchemaB OriginTestSchemaA0(this MySchemaSchema.TestSchemaA obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaB>().Where(c => c.OriginTestSchemaAID == obj.TestSchemaAID).First();
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA2
		/// </summary>
		[Association(ThisKey="TargetTestSchemaAId", OtherKey="TestSchemaAID", CanBeNull=false)]
		public static IQueryable<MySchemaSchema.TestSchemaA> TargetTestSchemaA(this MySchemaSchema.TestSchemaB obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaA>().Where(c => c.TestSchemaAID == obj.TargetTestSchemaAId);
		}

		/// <summary>
		/// FK_TestSchema_TestSchemaBY_TargetTestSchemaA2
		/// </summary>
		[Association(ThisKey="TargetTestSchemaAId", OtherKey="TestSchemaAID", CanBeNull=false)]
		public static MySchemaSchema.TestSchemaB TargetTestSchemaA0(this MySchemaSchema.TestSchemaA obj, IDataContext db)
		{
			return db.GetTable<MySchemaSchema.TestSchemaB>().Where(c => c.TargetTestSchemaAId == obj.TestSchemaAID).First();
		}

		#endregion

		#region TestSchemaX Associations

		/// <summary>
		/// FK_TestSchemaY_TestSchemaX_BackReference
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=true)]
		public static IQueryable<TestSchemaY> TestSchemaY(this TestSchemaX obj, IDataContext db)
		{
			return db.GetTable<TestSchemaY>().Where(c => c.TestSchemaXID == obj.TestSchemaXID);
		}

		/// <summary>
		/// FK_TestSchemaY_OtherID_BackReference
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=true)]
		public static IQueryable<TestSchemaY> TestSchemaYOtherIds(this TestSchemaX obj, IDataContext db)
		{
			return db.GetTable<TestSchemaY>().Where(c => c.TestSchemaXID == obj.TestSchemaXID);
		}

		/// <summary>
		/// FK_TestSchemaY_ParentTestSchemaX_BackReference
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="ParentTestSchemaXID", CanBeNull=true)]
		public static IQueryable<TestSchemaY> TestSchemaYParentTestSchemaX(this TestSchemaX obj, IDataContext db)
		{
			return db.GetTable<TestSchemaY>().Where(c => c.ParentTestSchemaXID == obj.TestSchemaXID);
		}

		#endregion

		#region TestSchemaY Associations

		/// <summary>
		/// FK_TestSchemaY_OtherID
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public static IQueryable<TestSchemaX> FkTestSchemaYOtherIds(this TestSchemaY obj, IDataContext db)
		{
			return db.GetTable<TestSchemaX>().Where(c => c.TestSchemaXID == obj.TestSchemaXID);
		}

		/// <summary>
		/// FK_TestSchemaY_OtherID
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public static TestSchemaY FkTestSchemaYOtherID(this TestSchemaX obj, IDataContext db)
		{
			return db.GetTable<TestSchemaY>().Where(c => c.TestSchemaXID == obj.TestSchemaXID).First();
		}

		/// <summary>
		/// FK_TestSchemaY_ParentTestSchemaX
		/// </summary>
		[Association(ThisKey="ParentTestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public static IQueryable<TestSchemaX> ParentTestSchemaX(this TestSchemaY obj, IDataContext db)
		{
			return db.GetTable<TestSchemaX>().Where(c => c.TestSchemaXID == obj.ParentTestSchemaXID);
		}

		/// <summary>
		/// FK_TestSchemaY_ParentTestSchemaX
		/// </summary>
		[Association(ThisKey="ParentTestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public static TestSchemaY ParentTestSchemaX0(this TestSchemaX obj, IDataContext db)
		{
			return db.GetTable<TestSchemaY>().Where(c => c.ParentTestSchemaXID == obj.TestSchemaXID).First();
		}

		/// <summary>
		/// FK_TestSchemaY_TestSchemaX
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public static IQueryable<TestSchemaX> TestSchemaX(this TestSchemaY obj, IDataContext db)
		{
			return db.GetTable<TestSchemaX>().Where(c => c.TestSchemaXID == obj.TestSchemaXID);
		}

		/// <summary>
		/// FK_TestSchemaY_TestSchemaX
		/// </summary>
		[Association(ThisKey="TestSchemaXID", OtherKey="TestSchemaXID", CanBeNull=false)]
		public static TestSchemaY TestSchemaX0(this TestSchemaX obj, IDataContext db)
		{
			return db.GetTable<TestSchemaY>().Where(c => c.TestSchemaXID == obj.TestSchemaXID).First();
		}

		#endregion

		#endregion
	}

	public static partial class MySchemaSchema
	{
		public partial class DataContext
		{
			public ITable<SameTableName> SameTableNames { get { return _dataContext.GetTable<SameTableName>(); } }
			public ITable<TestSchemaA>   TestSchemaA    { get { return _dataContext.GetTable<TestSchemaA>(); } }
			public ITable<TestSchemaB>   TestSchemaB    { get { return _dataContext.GetTable<TestSchemaB>(); } }

			private readonly IDataContext _dataContext;

			public DataContext(IDataContext dataContext)
			{
				_dataContext = dataContext;
			}
		}

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

		[Table(Schema="TestSchema", Name="TestSchemaA")]
		public partial class TestSchemaA
		{
			[Column(DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, NotNull] public int TestSchemaAID { get; set; } // int
			[Column(DbType="int", DataType=LinqToDB.DataType.Int32),             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 List<MySchemaSchema.TestSchemaB> FkTestSchemaTestSchemaBYTargetTestSchemaA2BackReferences { get; set; } = null!;

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

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

			#endregion
		}

		[Table(Schema="TestSchema", Name="TestSchemaB")]
		public partial class TestSchemaB
		{
			[Column(                           DbType="int", DataType=LinqToDB.DataType.Int32), PrimaryKey, NotNull] public int TestSchemaBID       { get; set; } // int
			[Column(                           DbType="int", DataType=LinqToDB.DataType.Int32),             NotNull] public int OriginTestSchemaAID { get; set; } // int
			[Column(                           DbType="int", DataType=LinqToDB.DataType.Int32),             NotNull] public int TargetTestSchemaAID { get; set; } // int
			[Column("Target_Test_Schema_A_ID", DbType="int", DataType=LinqToDB.DataType.Int32),             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 MySchemaSchema.TestSchemaA FKTargetTestSchemaA { get; set; } = null!;

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

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

			#endregion
		}

		public static partial class TestDataDBStoredProcedures
		{
			#region TestProcedure

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

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

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

			#endregion
		}

		#region Table Extensions

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

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

		#endregion
	}
}
