Hi
I want to use SelectLazy to get the first row of a table. I think Select will get all rows return from sql server.
Single do not have Order method. Am i right?
var plan =
Db.SelectLazy<UV_MITestPlan_UVChild>().Where(pl => pl.ChildId == childId && pl.MI_TestPlanId == planId).OrderByDescending(q=>q.PlanTime);
return plan.FirstOrDefault();
There’s no good reason to use SelectLazy to fetch a single result. Your query ends up being highly inefficient as you’re downloading and filtering all the results on the client. Use a normal query and perform the order by on the server, you can use Limit(rows:1) or Take(1) to fetch a single result.
Thanks for your help! But i can not understand your point.
I want to select one row by ormlite, the select operator is on the server, i find Db.Single method from document, but i can not use it order(may be i haven’t found it). How to write “Limit(rows:1)” and “Take(1)” by Ormlite.
Do you mean i should use sql directly,like top 1
db.Select<Track>(
"select top 1 from Track Where AlbumName = @album and TrackNo = @trackNo",
new { album = "Throwing Copper", trackNo = 3 })