0

For some reason I am getting a "Query body must end with a select clause or a group clause" compile error on what seems to be a simple compound conditional in the following linq-to-sql query:

using (var db = new CaremcDB(Database.Conn))
{
 var taxids = from p in db.ProviderTaxIds 
      join c in db.CustomerProviders
      on customerId equals c.CustomerId && p.Id equals c.ProviderId
      select p;

 return taxids.ToList<ProviderTaxIds>();
}

It chokes on the "&& p.Id equals c.ProviderId" clause for some reason.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148
BillyM2010
  • 13
  • 1
  • 3

2 Answers2

3

It appears that customerId is an external input to the query. Move that to a where clause.

...
on p.Id equals c.ProviderId  
where customerId == c.CustomerId
select p;
Anthony Pegram
  • 123,721
  • 27
  • 225
  • 246
  • That works for some reason. But it also compiles if I remove the "&& p.Id equals c.ProviderId" (which isn't what I want, but just testing the ability to compile.) It is very puzzeling as it seems this should be rather straight-forward. – BillyM2010 Jul 05 '11 at 16:52
  • @Billy, The `&&` portion is the problem. Another user posted a way to do a compound-field join via anonymous typing, but you really don't need to do that in this specific case. – Anthony Pegram Jul 05 '11 at 16:55
  • Using the where clause works. I take it that && is not allowed on a join for some reason. – BillyM2010 Jul 05 '11 at 17:41
1

try this, the parameter names just need to match in the anonymous object

join c in db.CustomerProviders on new { customerId, p.Id } equals new { customerId = c.CustomerId, Id= c.ProviderId }

Jeremy Gray
  • 1,378
  • 1
  • 9
  • 24