1

I'm writing a fluent API (been upgrading EntitySpaces) and I want to have this syntax ...

EmployeeQuery q = new EmployeeQuery("q");
q.Select(q.Id > () =>  // Notice Func<> syntax here, this won't compile !!!!
    {
        return new EmployeeQuery("e", out var q1)
        .Where(q1.Id.IsNotNull()).All();
    })
); 

But you guess it, compile error. I overload all of the operators in my syntax and everything works but I cannot get this syntax to work, I think the ">" followed by the "() =>" syntax just confuses the compiler entirely and it could never actually work?

Note that above "q.Id" in the Select() methods returns an esQueryItem, thus the overload below ...

Here is my overload ...

public class esQueryItem
{
    public static esComparison operator >(esQueryItem item, Func<esDynamicQuery> func)
    {
        return null;
    } 

    public static esComparison operator <(esQueryItem item, Func<esDynamicQuery> func)
    {
        return null;
    }
} 
Olivier
  • 129
  • 9
  • 4
    What would be the expected behavior in this scenario? Your asking whether something is greater than a function? – Mark Davies Dec 19 '19 at 15:25
  • 2
    `q.Id > ( () => ...) ()` ? – Sinatr Dec 19 '19 at 15:25
  • No, this code in the end is merely a definition for a SQL query, the resulting code would be something like: SELECT q.ID] FROM [Employee] 1 WHERE q.ID > ALL ( SELECT ... (nested query on other side of > ) – Mike Griffin Dec 19 '19 at 15:31
  • You're using a `>` operator on a type that's not `esQueryItem` (unless `q.Id` is `esQueryItem`)? – Matt U Dec 19 '19 at 15:32
  • CodeCaster, you have to overload all operators to make the syntax fluent, see https://mikegriffinreborn.github.io/EntitySpaces/ for examples. Just forget the EntitySpaces part, try it for an int and see if you can get to work if you're interested ... `code` int i = 9; if (i == () => { 5 } ) { } `code` – Mike Griffin Dec 19 '19 at 15:34
  • Matt, yes, q.Id returns an esQueryItem – Mike Griffin Dec 19 '19 at 15:34

1 Answers1

0

Sinatr, you got it, thanx ... I don't want the last set of "()" because I don't want to execute the function, the function get's executed inside the Func<> itself, again thanx

EmployeesQuery q = new EmployeesQuery("q");
q.Where(q.EmployeeID > (() =>
    {
        return new EmployeesQuery("e", out var q1)
        .Select(q1.EmployeeID)
        .Where(q1.EmployeeID.IsNotNull()).Any();
    })
);

This generates ...

SELECT * FROM [Employees] q 
WHERE q.[EmployeeID] > ANY 
(
    SELECT e.[EmployeeID] 
    FROM [Employees] e 
    WHERE e.[EmployeeID] IS NOT NULL
)