jonpryor / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
0 stars 0 forks source link

Table missing when table, used implicitly in select-clause, is used explicitly in where-clause #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Using the sample Northwind database on an Oracle server and using a
DataContext to it named "nwind", a query is created where foreign keys is
followed through 3 tables in the where-clause the same chain is followed 2
tables deep (the "et.EmployeeID" expression is also selected here to guard
against a different bug):

var q = nwind.EmployeeTerritories
  .Where(et => et.Territories.TerritoryDescription == "foo")
  .Select(et => new { et.EmployeeID,
                      et.Territories.Region.RegionDescription })
  .ToList();

What is the expected output? What do you see instead?
I would expect a valid sql-query be generated, the database queried without
error, but no rows should probably be returned.

Instead I get an OracleException "ORA-00918: column ambiguously defined".
Looking at the generated query (wrapped for readability), it turns out that
an alias is missing in the expressing "(t2$.REGIONID = REGIONID)" (the
missing alias is "t1$"):

SELECT et$.EMPLOYEEID, t2$.REGIONDESCRIPTION
FROM NORTHWIND.EMPLOYEETERRITORIES et$,
     NORTHWIND.REGION t2$,
     NORTHWIND.TERRITORIES t1$
WHERE (t2$.REGIONID = REGIONID)
AND (t1$.TERRITORYID = et$.TERRITORYID)
AND (t1$.TERRITORYDESCRIPTION = 'foo')

What version of the product are you using? On what operating system?
Using the svn-version (revision 1304)

Please provide any additional information below.
The problem seems to be in the method:
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.RegisterAssociation(.
..)
It seems to be called to get a table expression for a member. First it
creates a new table expression for the member and the checks if the
expression has already been added to the current scope. It it hasn't it is
added and returned. If, on the other hand, an equivalent expressing have
already been added, the new expressing isn't added, but the new (non-added)
expression is still returned. This mean that when enumerating the scope, to
set table aliases, this new table isn't handled.

The attached patch changes the last case, such that if an equivalent
expression have already been added to the scope, this existing expression
is returned.

Original issue reported on code.google.com by anders...@gmail.com on 6 Feb 2010 at 3:17

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1310.

Original comment by jonmpr...@gmail.com on 10 Mar 2010 at 7:36

GoogleCodeExporter commented 9 years ago
Closing.

Original comment by jonmpr...@gmail.com on 9 Apr 2010 at 7:54