iqtoolkit icon indicating copy to clipboard operation
iqtoolkit copied to clipboard

database column name differing from member name leads to incorrect query

Open jmkinzer opened this issue 1 year ago • 0 comments

Please note this applies to the modern branch.

Minimal example based on the Northwind tests. This leads to the association between the tables being lost and so the resultant SQL lacks the where exists clause.

var res = someProvider.GetTable<Customer>().Select(c => new { c.CustomerID, c.Orders });
var qp = someProvider.GetQueryPlan(res.Expression);
Console.WriteLine(qp.QueryText);

[Table(Name = "Customers")]
public class Customer
{
    //[Column(Name = "CustomerID")] ok
    [Column(Name = "CustomerID1")]
    public string CustomerID;

    [Association(KeyColumns = nameof(CustomerID))]
    public List<Order> Orders;// = new List<Order>();
}

[Table(Name = "Orders")]
public class Order
{
   //[Column(Name = "CustomerID")] ok
    [Column(Name = "CustomerID1")]
    public string CustomerID;
}

Result:

SELECT t0."CustomerID1"
FROM "Customers" AS t0

SELECT t0."CustomerID1"
FROM "Orders" AS t0

jmkinzer avatar Sep 09 '24 04:09 jmkinzer