Hi,
Is there faster way to code finding only one entity using .Where() ?
For example product entity has barcode field which is unique but not primary key (can contain empty values but exists values are unique).
Now i think the best solution is with class helper
function TomHelper.FindOne<t>(aCrit: TCustomCriterion ): t;
var
lList: tlist<t>;
begin
lList := Find<t>.where(aCrit).list ;
try
if lList.Count> 0 then
result := lList[0]
else
result := nil;
finally
llist.Free;
end;
end;
And then call
lproduct := lObjMgr.findOne<tProduct>(Linq['barcode'] = aBarcode);
Haven't actually checked how much overhead comes from creating a list, but my internal ms-dos programer inside my heads screams...