score:3
The standard Zip
method allows you to write something like (using C#):
from t in first.Zip(second, (f, s) => new { First = f, Second = s }
select ... t.First ... t.Second;
I think this should be readable enough. Your question seems to suggest that you'd like to be able to create your own keyword e.g. zip
and extend the C# query expressions using it. This is not possible in C# or Visual Basic (but I agree it would be nice in a way).
With some effort, you can redefine what standard C# query construct does, so that join
would behave like zip
(In that case, the equals
part of the query would not be needed, so you'd have a lot of syntactic noise). Possibly, you could also redefine what from
clause. I didn't try it, but I believe you could get something like:
from f in first.Zip()
from s in second.AddToZip()
from t in second.AddToZip()
select ... f ... s ... t ...;
I wrote an article that describes how to do this redefining for the group by
clause (Using custom grouping operator in LINQ), so this can give you an idea how this can be done.
(But honestly, I think that the standard Zip
method should be fine. The redefinition of operators is quite subtle. The group by
example may be more appealing because grouping using method is uglier, but even that is on the edge...)
Source: stackoverflow.com
Related Articles
- LINQ multiple join IQueryable modify result selector expression
- Left outer join using LINQ -- understanding the code
- Linq left outer join with custom comparator
- How to reuse a linq expression for 'Where' when using multiple source tables
- Conditional operator in Linq Expression causes NHibernate exception
- Is LINQ Join operator using Nested Loop, Merge, or HashSet Joins?
- Linq to CRM (early bound) join statement throws exception when lambda expression doesn't
- LINQ Source Code Available
- linq join operator type with lambda syntax
- How can I code an outer join using LINQ and EF6?
- How to use AND operator in LINQ Join
- How to create a custom store expression for my linq queries
- Can't use ternary operator to assign Linq expression
- How do I get this Linq query with custom join into a DataSet?
- creating Linq to sqlite dbml from DbLinq source code
- Linq to Sql: Optimizing lamba expression - clean code
- Multiple Join Statements with LEFT JOIN to LINQ Expression syntax
- Join columns in LINQ and run contains operator
- How and I introduce an "or" operator into a linq query join
- C# Linq expression for nested left join
- Linq expression multiple left outer join error
- Sorting LINQ 'GroupBy' operator keys into a custom order
- linq lambda expression and '&' operator
- Add between clause in a LINQ expression with OR operator
- Construct AndAlso/OrElse LINQ expression with custom method
- Linq in conjunction with custom generic extension method build error - An expression tree may not contain an assignment operator?
- Can you zip or use a custom join operator in non-expression linq?
- How can I use Linq expression for Join with GroupBy in EF Core 3.1
- LINQ to Object Join operator and equality
- Creating a custom IEnumerable.Contains LINQ Expression
- join excel and access using Linq query
- Merge two XML files and add missing tags and attributes
- Many-to-Many Select second order
- Query against a Deserialized JSON object
- How to reuse code inside a Expression<Func< ... >>?
- Linq Equivalent to Where Clause with Nested Conditions
- Select X with Max(F(X))
- How to optimize and pre-compile this LINQ expression?
- Batch Update From a LINQ Query?
- Need help with a LINQ Query using the Dynamic LINQ Library
- Using LINQ to select EF properties in DBSet with specific Attributes
- C# LinqToExcel, Distinct showing all results - tried online solutions, couldn't solve
- Get Next Meeting Date fails using Linq query
- Dynamic "WHERE" like queries on memory objects
- Is it possible to concat strings when grouping with Linq?
- aggregation result from SQL view to gridview
- Method to get a summary view from a dataset
- Why is my linq to SQL query very slow?
- Linq Query Crash if Return Null
- linq clause with multiple on clause with arithmetic