The more "SQL-syntax" of Linq.Except
c#, linq, syntax
Solution
Are there formal names for what I'm calling Method-form and SQL-like syntax?
Yes one is Method Syntax and the other (SQL like) is query syntax (query expression written in query sytnax).
LINQ Query Expressions (C# Programming Guide)
Query expressions are written in a declarative query syntax introduced in C# 3.0.
See: Query Syntax and Method Syntax in LINQ (C#)
For your other question:
Is there a way to do the SQL-like-syntax on the except operation?
No. I haven't seen `Except` with query syntax.
See: Query Syntax and Method Syntax in LINQ (C#)
Most queries in the introductory Language Integrated Query (LINQ) documentation are written by using the LINQ declarative query syntax. However, the query syntax must be translated into method calls for the .NET common language runtime (CLR) when the code is compiled. These method calls invoke the standard query operators, which have names such as Where, Select, GroupBy, Join, Max, and Average. You can call them directly by using method syntax instead of query syntax.
So it appears you can only use `Where, Select, GroupBy, Join, Max, and Average` with Query Syntax.
Problem
Most expressions in Linq can be written in two syntaxs. Basically, the Method-syntax and the SQL-like-syntax. For example: Method-syntax: `var results = MySet.Where(n => n.Status == State.ACTIVE);` SQL-like-syntax: `var results = from n in MySet where n.Status == State.ACTIVE select n;` I'd like to use `.Except` in the SQL-like-syntax, but can only find examples online where it is used in the Method-syntax. Example: ``` int[] numbers = Enumerable.Range(1,20).ToArray(); int[] primes = new[] { 2, 3, 5, 7, 11, 13, 17 }; //var composites = from n in numbers select n except primes; // This does not work. var composites = numbers.Except(primes); // This works return composites; ``` Questions Are there formal names for what I'm calling Method-syntax and SQL-like-syntax? Is there a way to do the SQL-like-syntax on the `except` operation?