Created
September 18, 2014 12:30
-
-
Save ianfnelson/0fd94841097a75fa9d58 to your computer and use it in GitHub Desktop.
Snippets for 2009 blog post "Testing LINQ Queries"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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