I haven’t tested this on other dialects, but just ran into some bizarre behavior that took me a while to track down.
I have a method like this:
public static T GetOrCreateLookupRecord<T>(this IServiceContext serviceContext, T record) where T: ILookup, new()
{
var lkp = serviceContext.Db.Single<T>(r => r.Name == record.Name);
if (lkp != null) return lkp;
if (record.Id == Guid.Empty) record.Id = Guid.NewGuid();
serviceContext.Db.Insert(record);
return record;
}
When I look at the sql generated here: serviceContext.Db.Single<T>(r => r.Name == record.Name);
, it looks like this (which obviously is wrong, or at least not what I expected).
SELECT "Id", "Name"
FROM "dis_lkp_pis"
WHERE ("Name" = "Name")
LIMIT 1
Doing the following works though:
var name = record.Name;
var lkp = serviceContext.Db.Single<T>(r => r.Name == name);
which generates the sql
SELECT "Id", "Name"
FROM "dis_lkp_offices"
WHERE ("Name" = @0)
LIMIT 1
Is this a bug? and if not, how do I rationalize it so I don’t run into this sort of expression evaluation issue in the future, because I wouldn’t have ever thought this could be an issue.