I came across code like:
var vpAlias = null; var prices = session.QueryOver<Vehicle>() .Left.JoinAlias<VehiclePrice>(x => x.VehiclePrice, () => vpAlias, x => x.VehiclePriceTypeId == 1) .Where(() => vpAlias.Id == null || vpAlias.VehiclePriceTypeId == 1) .Select(x => x.Id, () => vpAlias.Price) .ToList();
which uses () in its lambda expressions. What does it mean? Is it used as a placeholder?
()
It just means that this is an empty parameter list - for delegate types that have no parameters.
The fact that you can write x => x.Id is actually just a shorthand for (x) => x.Id , which in turn is a shorthand for (Vehicle x) => x.Id This is just a list of options.
x => x.Id
(x) => x.Id
(Vehicle x) => x.Id
This is the same as empty () in:
static SomeType YourNamedMethod() { return vpAlias; }
The parentheses contain a list of parameters. Only if you have only one parameter, you can leave them. Examples:
0 parameters: () => result
() => result
1 parameter: (x) => result or x => result
(x) => result or x => result
2 parameters: (x, y) => x + y;
(x, y) => x + y;
() => { ... } is Func<TOut> , so it does not accept anything as input, you can see it as
() => { ... }
Func<TOut>
<returnType> MyFunction () { // Code goes here }