Skip to content

Instantly share code, notes, and snippets.

@ianfnelson
Created September 18, 2014 12:30
Show Gist options
  • Save ianfnelson/0fd94841097a75fa9d58 to your computer and use it in GitHub Desktop.
Save ianfnelson/0fd94841097a75fa9d58 to your computer and use it in GitHub Desktop.
Snippets for 2009 blog post "Testing LINQ Queries"
/// <summary>
/// Finds leads in the repository by Customer Name.
/// </summary>
/// <param name="repo" />Repository of Leads</param>
/// <param name="customerName" />Customer name</param>
/// <returns>Leads matching the criteria</returns>
public static IQueryable<Lead> ByCustomerName(this IQueryable<Lead> repo, string customerName)
{
if (customerName.IsNullOrEmpty())
{
return repo;
}
return repo
.Where(
l => l.Customers.Any(c => c.Name.Contains(customerName)));
}
return this.leadRepository
.ByAllocatedUserId(query.AllocatedUserId)
.ByClosed(query.Closed)
.ByCustomerId(query.CustomerId)
.ByCustomerName(query.CustomerName)
.ByLeadTypeIds(query.LeadTypeIds)
.ByProjectId(query.ProjectId)
.ByScapeId(query.ScapeId)
.ByStarred(query.Starred)
.Sort(sortField, sortDescending)
.Skip(offset)
.Take(maximumResults)
.ToDto()
.ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment