I have the following code:
public void SalesCount(string customerId)
{
..
..
return ...;
}
var resultQuery = dataContext.Customers
.Where (c => c.Name == "Alugili")
.Where (c => SalesCount(c.CustomerId) < 100);
When I execute resultQuery I get a translation to SQL exception.
I need to call SalesCount in the Where can I do that is there any workaround for this problem!
SalesCount
is doing in T-SQL ? If so, try to make a VIEW which represents theCustomers
table but adds an extra column (the result ofSalesCount
). Then map that VIEW in your LINQ to SQL entities, and perform selects on that entity. In this manner, you avoid bringing a load of records to be treated in .NET and let the RDBMS do it for you.