New issue 190 by vladislav.iofe: Using wrong alias when joining tables
http://code.google.com/p/dblinq2007/issues/detail?id=190
Using wrong alias when joining the same table.
ver0.19.
1. Create self-referencing entity with fields ID and IDParent
2. Insert two record into entity's table, the second entry references to
the first.
3. Run the code:
var query = (
from cf in dc.Folder
join cf2 in dc.Folder on cf.IDParent equals cf2.ID
select cf2
).Distinct();
var list = query.ToArray();
Expected: the first entity
Actual: empty list
Result SQL query:
SELECT DISTINCT cf2$.dt_created, cf2$.dt_modified, cf2$.full_path, cf2$.id,
cf2$.id_parent, cf2$.key_type, cf2$.name
FROM public.folder cf$, public.folder cf2$
WHERE (cf$.id_parent = cf$.id)
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
Comment #1 on issue 190 by jonmpryor: Using wrong alias when joining tables
http://code.google.com/p/dblinq2007/issues/detail?id=190
For those like me who need an eagle eye, the problem is the final WHERE
clause -- the
alias name is wrong. It's:
WHERE (cf$.id_parent = cf$.id)
but should be:
WHERE (cf2$.id_parent = cf$.id)
try to change, in the TableExpression.cs, the IsEqualTo method, to this:
public virtual bool IsEqualTo(TableExpression expression)
{
return (Name == expression.Name && JoinID == expression.JoinID
&&
(Alias == null || expression.Alias == null
|| Alias.Equals(expression.Alias)));
}