Skip to content

column not in scope in specific situation #15

@TomWouters

Description

@TomWouters

Hello Matthew and other contributors,

I'm Tom Wouters, a senior architect working on a solution based on iqtoolkit for advanced mapping.
We currently use iqtoolkit as our core engine and we're really happy about it, but I'm faced with a very specific issue.

When we create a request for a table with a collection and in that collection 2 sub items (trigger is more than one sub relation), the program gives a column not in scope error.
To my opinion it should be possible with iqtoolkit, because this situation works in the root (a table with more than one sub query), only the scope either gets build incorrectly
when a one to many memberbinding is constructued, or the construction of a one to many memberbinding itself is called incorrectly.

So basically working:

X

  • CollectionOfY
    • Z

and
X

  • CollectionOfY
    • CollectionOfZ
      and

X

  • Z
  • Y
  • -   V
    
  • -   U
    

But what isn't working is:

X

  • CollectionOfY
    • Z
    • V

or

X

  • CollectionOfY
    • CollectionOfZ
    • V

As an example I modified the current Orders to have a direct link to a product (yes I know, it's completely illogical, but it gets the trick done), updated the northwind.db3 database to reflect the changes (all orders are connected to product 1)

changes:

Test.Common\Northwind.cs

From

public class Order
{
    public int OrderID;
    public string CustomerID;
    public DateTime OrderDate;
    public Customer Customer;
    public List<OrderDetail> Details;
}

To

public class Order
{
    public int OrderID;
    public string CustomerID;
    public DateTime OrderDate;
    public Customer Customer;
    public List<OrderDetail> Details;
    public int ProductID { get; set; } //*new*
    public Product Product; //*new*
}

From

    [Table]
    [Column(Member = "OrderID", IsPrimaryKey = true, IsGenerated = true)]
    [Column(Member = "CustomerID")]
    [Column(Member = "OrderDate")]
    [Association(Member = "Customer", KeyMembers = "CustomerID", RelatedEntityID = "Customers", RelatedKeyMembers = "CustomerID")]
    [Association(Member = "Details", KeyMembers = "OrderID", RelatedEntityID = "OrderDetails", RelatedKeyMembers = "OrderID")]
    public override IEntityTable<Order> Orders
    {
        get { return base.Orders; }
    }

To

	[Table]
    [Column(Member = "OrderID", IsPrimaryKey = true, IsGenerated = true)]
    [Column(Member = "CustomerID")]
    [Column(Member = "OrderDate")]
    [Column(Member = "ProductId")] //*new*
    [Association(Member = "Customer", KeyMembers = "CustomerID", RelatedEntityID = "Customers", RelatedKeyMembers = "CustomerID")]
    [Association(Member = "Details", KeyMembers = "OrderID", RelatedEntityID = "OrderDetails", RelatedKeyMembers = "OrderID")]
    [Association(Member = "Product", KeyMembers = "ProductID", RelatedEntityID = "Products", RelatedKeyMembers = "ID")]  //*new*
    public override IEntityTable<Order> Orders
    {
        get { return base.Orders; }
    }

And in Test.Common\NorthwindExecutionTests.cs

I added the test:

	public void TestCustomersIncludeOrdersAndDetailsAndCustomer()
    {
        var policy = new EntityPolicy();
        policy.IncludeWith<Customer>(c => c.Orders);
        policy.IncludeWith<Order>(o => o.Details);
        policy.IncludeWith<Order>(o => o.Product);
        Northwind nw = new Northwind(this.GetProvider().New(policy));

        var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
        Assert.Equal(1, custs.Count);
        Assert.NotEqual(null, custs[0].Orders);
        Assert.Equal(6, custs[0].Orders.Count);
        Assert.Equal(true, custs[0].Orders.Any(o => o.OrderID == 10643));
        Assert.NotEqual(null, custs[0].Orders.Single(o => o.OrderID == 10643).Details);
        Assert.Equal(3, custs[0].Orders.Single(o => o.OrderID == 10643).Details.Count);
    }

As test engine, I used the Test.Sqlite because we're mainly using a sqlite db. In order to have test.sqlite run, I added a reference to IQToolkit.Data.SQLite
and in the main call of program.cs, I added var _x = typeof(SQLiteFormatter); (so that the sqlite assembly is loaded)

Could you guys give me a pointer on where the issue is located? Or maybe even solve it?
I spent more then a week narrowing the issue down, and trying to find a logical place on where to fix it, but I really can't seem to wrap my head around it.

The zip file contains the northwind.db3 changed db, the NorthwindExecutionTests.cs and Northwind.cs

ChangesForTest.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions