Queryable.UnionBy Method

Definition

Overloads

UnionBy<TSource,TKey>(IQueryable<TSource>, IEnumerable<TSource>, Expression<Func<TSource,TKey>>)

Produces the set union of two sequences according to a specified key selector function.

UnionBy<TSource,TKey>(IQueryable<TSource>, IEnumerable<TSource>, Expression<Func<TSource,TKey>>, IEqualityComparer<TKey>)

Produces the set union of two sequences according to a specified key selector function.

UnionBy<TSource,TKey>(IQueryable<TSource>, IEnumerable<TSource>, Expression<Func<TSource,TKey>>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

Produces the set union of two sequences according to a specified key selector function.

C#
public static System.Linq.IQueryable<TSource> UnionBy<TSource,TKey>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector);

Type Parameters

TSource

The type of the elements of the input sequences.

TKey

The type of key to identify elements by.

Parameters

source1
IQueryable<TSource>

An IQueryable<T> whose distinct elements form the first set for the union.

source2
IEnumerable<TSource>

An IEnumerable<T> whose distinct elements form the second set for the union.

keySelector
Expression<Func<TSource,TKey>>

A function to extract the key for each element.

Returns

IQueryable<TSource>

An IEnumerable<T> that contains the elements from both input sequences, excluding duplicates.

Exceptions

source1 or source2 is null.

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9

UnionBy<TSource,TKey>(IQueryable<TSource>, IEnumerable<TSource>, Expression<Func<TSource,TKey>>, IEqualityComparer<TKey>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

Produces the set union of two sequences according to a specified key selector function.

C#
public static System.Linq.IQueryable<TSource> UnionBy<TSource,TKey>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer);

Type Parameters

TSource

The type of the elements of the input sequences.

TKey

The type of key to identify elements by.

Parameters

source1
IQueryable<TSource>

An IQueryable<T> whose distinct elements form the first set for the union.

source2
IEnumerable<TSource>

An IEnumerable<T> whose distinct elements form the second set for the union.

keySelector
Expression<Func<TSource,TKey>>

A function to extract the key for each element.

comparer
IEqualityComparer<TKey>

The IEqualityComparer<T> to compare values.

Returns

IQueryable<TSource>

An IEnumerable<T> that contains the elements from both input sequences, excluding duplicates.

Exceptions

source1 or source2 is null.

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9