I am trying to join two tables together using C# linq to entities.
One table has clients, the other table has licences. The tables are joined by Client_ID and ClientLicence_ClientID. For some reason (they are not my tables) the Client_ID is an int, and the ClientLicence_ClientID is a string.
The code I have is:
var licences = (from client in entities.Clients
join licence in entities.ClientLicences
on new { clientId = SqlFunctions.StringConvert((double)client.Client_ID) } equals
new { licence.ClientLicence_ClientID }
into clientGroup
where (filter.clientId == 0 || client.Client_ID == filter.clientId)
select licence);
When I try to compile this I get an error: The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.
If I comment out the where statement then it works (albeit without filtering results).
The filter variable is a class that is passed in to the function. It only has one propery: int clientId.