SelectMany support without needing to mantain the parameter name
Description
Hi,
var items = parent.SelectMany( x=>x.Items ).Where( x => x.Bla == 3 ).ToList() doesn't work. we need to specify the result selector just for knowing the alias name, so it needs the paramenter name to be maintained between expressions. so:
var items = parent.SelectMany( x=>x.Items, (p,r) => r ).Where( r => r.Bla == 3 ).ToList() works but
var items = parent.SelectMany( x=>x.Items, (p,r) => r ).Where( x => x.Bla == 3 ).ToList() doesn't
I can't see a reason why the alias is the parameter name. I mean, I can't find a scenario when this could be needed. With criteria one can do something like var c = session.CreateCriteria( type ); var p1 = c.CreateCriteria( "foo" ).Add( Expression.Eq( "XXXX", 5 ); var p2 = c.CreateCriteria( "bar" ).Add( Expression.Gt( "YYYY", 10 );
var result = p1.List<Foo>();
but with linq, we only have one single path, right? so, the queryable could have the "current path alias" and when SelectMany is called, change the alias.
Just to be sure, I changed the AssociationVisitor class for accepting only one path an every test were green.
I will be attaching a patch for this today or tomorrow, but first I want to know if I'm right with my train of thought.
Hi,
var items = parent.SelectMany( x=>x.Items ).Where( x => x.Bla == 3 ).ToList() doesn't work. we need to specify the result selector just for knowing the alias name, so it needs the paramenter name to be maintained between expressions. so:
var items = parent.SelectMany( x=>x.Items, (p,r) => r ).Where( r => r.Bla == 3 ).ToList() works but
var items = parent.SelectMany( x=>x.Items, (p,r) => r ).Where( x => x.Bla == 3 ).ToList() doesn't
I can't see a reason why the alias is the parameter name. I mean, I can't find a scenario when this could be needed.
With criteria one can do something like
var c = session.CreateCriteria( type );
var p1 = c.CreateCriteria( "foo" ).Add( Expression.Eq( "XXXX", 5 );
var p2 = c.CreateCriteria( "bar" ).Add( Expression.Gt( "YYYY", 10 );
var result = p1.List<Foo>();
but with linq, we only have one single path, right? so, the queryable could have the "current path alias" and when SelectMany is called, change the alias.
Just to be sure, I changed the AssociationVisitor class for accepting only one path an every test were green.
I will be attaching a patch for this today or tomorrow, but first I want to know if I'm right with my train of thought.
Thanks