Skip to content

Instantly share code, notes, and snippets.

@dhont
Created October 11, 2016 17:24
Show Gist options
  • Save dhont/4d38d13e9a13bdad066fce9706fad888 to your computer and use it in GitHub Desktop.
Save dhont/4d38d13e9a13bdad066fce9706fad888 to your computer and use it in GitHub Desktop.
public static class EfBuilderExtensions
{
/// <summary>
/// super simple and dump translation of .Contains because is not supported pe EF plus
/// this translates to contains in EF SQL
/// </summary>
/// <param name="source"></param>
/// <param name="contains"></param>
/// <returns></returns>
public static IQueryable<Raspuns> WhereRaspunsContains(this IQueryable<Raspuns> source, IList<int> contains)
{
var ors = contains
.Aggregate<int, Expression<Func<Raspuns, bool>>>(null, (expression, id) =>
expression == null
? (a => a.IdIntrebare == id)
: expression.Or(a => a.IdIntrebare == id));
return source.Where(ors);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment