我有这两行,它们做的事情完全一样。但是写的不一样。哪个是更好的做法,为什么?
firstRecordDate = (DateTime)(from g in context.Datas
select g.Time).Min();
firstRecordDate = (DateTime)context.Datas.Min(x => x.Time);
最佳答案
there is no semantic difference between method syntax and query syntax. In addition, some queries, such as those that retrieve the number of elements that match a specified condition, or that retrieve the element that has the maximum value in a source sequence, can only be expressed as method calls.
http://msdn.microsoft.com/en-us/library/bb397947.aspx
另请参阅此处:.NET LINQ query syntax vs method chain
这归结为您对什么感到满意以及您发现什么更具可读性。
关于c# - 哪个是使用 LINQ 的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7124169/