Using Linq to SQL, how do I find min and max of a column in a table?

前端 未结 5 1260
情书的邮戳
情书的邮戳 2020-12-29 03:40

I want to find the fastest way to get the min and max of a column in a table with a single Linq to SQL roundtrip. So I know this would work in two roundtrips:



        
5条回答
  •  清酒与你
    2020-12-29 04:09

    You could select the whole table, and do your min and max operations in memory:

    var cache = // select *
    
    var min = cache.Min(...);
    var max = cache.Max(...);
    

    Depending on how large your dataset is, this might be the way to go about not hitting your database more than once.

提交回复
热议问题