score:7
You need to use a single where
_collection.Where(x => x.ByIdA() || x.ByIdB());
score:4
LINQ probably isn't the way to solve this one. Each LINQ method acts independently, so if you managed to get your OR in a chain like this, it would difficult to read, and definitely difficult to understand and debug.
You probably just want to OR the old fashioned way:
_something.Entity.Where(x => IsA(x) || IsB(x))
score:6
score:0
For the first part of your question could use:
var list = _something.Entity;
var result = Enumerable.Union(list.ByIdA(), list.ByIdB());
But for the second part, which seems another question, There's need to clarify the question. If you mean that each of A objects has a list of B(s) and You want all A objects which A.x==1
or A.Bs.Any(b=>b.y==1)
then you could use:
var result = list.Where(a => a.x==1 || a=>a.Bs.Any(b=>b.y==1));
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Syntax to execute code block inside Linq query?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ WHERE method alters source collection
- Where can I view LINQ source code?
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Left outer join using LINQ -- understanding the code
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- How does linq actually execute the code to retrieve data from the data source?
- How can I switch that code to use LINQ
- How does this linq code that splits a sequence work?
- multiple orderby in this linq code
- How can I combine this code into one or two LINQ queries?
- Linq with where clause in many-to-many EF Code First object
- LINQ and dynamic strong types
- Enumerable.Repeat with Union and Take does not return 'Take' values
- Mongo DB Join array in 2 different collections
- Given a Member Access lambda expression, convert it to a specific string representation with full access path
- How to calculate employees reporting to a manager recursively using LINQ?
- insert items to Top from list to the same list after filtering
- Convert foreach to LINQ statement
- How to improve performance of my linq query?
- EF: IQueryable not loading children
- call sum in expression tree
- unable to create a constant value of type 'yyy'. only primitive types or enumeration types are supported in this context
- LINQ Union between two tables with the same fields and then returned in a collection
- Invert and flatten a dictionary using LINQ
- Some help to make LINQ clause properly work
- SQL query with ROW_NUMBER not efficient in LINQ
- Convert SQL sub query to LINQ in C#
- Joining two tables in one datagrid usig Linq C# WPF
- sql Top 1 vs System.Linq firstordefault
- LINQ query that calls some method for additional calculations
- LINQ query from XML and unknown subitems plus container type?