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

前端 未结 5 1262
情书的邮戳
情书的邮戳 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:03

    I'm not sure how to translate it into C# yet (I'm working on it)

    This is the Haskell version

    minAndMax :: Ord a => [a] -> (a,a)
    minAndMax [x]    = (x,x)
    minAndMax (x:xs) = (min a x, max b x)
                       where (a,b) = minAndMax xs
    

    The C# version should involve Aggregate some how (I think).

提交回复
热议问题