I'm trying to write a simple query that requires an alias as it's a Many-To-Many assocation however I can't get it to work with NH Lambda Extensions. It always gives me a compile error even though as far as I can tell it's exactly the same as the documentation and all the examples I've seen online.
Works
var query = DetachedCriteria.For<County>()
.CreateCriteria("Zips", "zipAlias", JoinType.LeftOuterJoin)
//.CreateCriteria<County>(x => x.Zips,
// () => zipAlias, JoinType.LeftOuterJoin)
.Add<Zip>(zip => zip.ZipCode == zipCode);
Doesn't work
var query = DetachedCriteria.For<County>()
//.CreateCriteria("Zips", "zipAlias", JoinType.LeftOuterJoin)
.CreateCriteria<County>(x => x.Zips,
() => zipAlias, JoinType.LeftOuterJoin)
.Add<Zip>(zip => zip.ZipCode == zipCode);
Results in a build Error 22 The name 'zipAlias' does not exist in the current context
Intellisense also highlights the CreateCriteria**<County>
** saying it doesn't understand the method however it does correctly show me the parameter names when I'm inside the parens.
The documentation is full of handy examples.
Your
zipAlias
needs to be a variable in the local scope.As the documentation link downloads instead of rendering, I have copied some sections.
Create Criteria Association With Alias
Using original ICriteria API:
Using NHibernate Lambda Extensions:
Create Criteria Alias Association With Alias And Join Type
Using original ICriteria API:
Using NHibernate Lambda Extensions:
Create Criteria Association With Alias And Join Type
Using original ICriteria API:
Using NHibernate Lambda Extensions: