// The following statement does not compile due to error in lambda with "==" operator
// "Operator '==' cannot be applied to operands of type 'TId' and 'TId'"
query = query.Where((Expression<Func<TEntity, bool>>)(i => i.Id == id));

var sql = query.ToSQL().ToQuery();
return sql;
}

Adding a

where TId: class

generic constraint resolves the problem but since my TId are in most cases value types (mainly

int

,

long

,

Guid

) it does not match my needs. And the generic constraint

where TId: struct

does not make it compile. I understand the reasons why this happens (thanks to this thread).

The interface for the entity is

public interface IHasAnIdField<TId>
{
TId Id { get; }
}

I cannot use a

.Equal(..)

call or any

EqualityComparer

since a method call in the Expression tree is not handled by the SQLinq tool.