Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LINQ方法语法中的Order by_Linq_Asp.net Mvc 3_Sql Order By - Fatal编程技术网

LINQ方法语法中的Order by

LINQ方法语法中的Order by,linq,asp.net-mvc-3,sql-order-by,Linq,Asp.net Mvc 3,Sql Order By,我已经尝试在每个可能的位置将orderby插入到这个查询中,但无法让它工作。在这个linq查询中,我提取了一个与单个属性相关的unitMixes列表。在unitMixes表中有一个名为createDate的字段,我想根据该字段对结果进行排序,这看起来很简单,但我还不能完全理解我的中间方法语法 var viewModel = new propertyDetailData(); viewModel.properties = db.properties.Where(s => s.property

我已经尝试在每个可能的位置将orderby插入到这个查询中,但无法让它工作。在这个linq查询中,我提取了一个与单个属性相关的unitMixes列表。在unitMixes表中有一个名为createDate的字段,我想根据该字段对结果进行排序,这看起来很简单,但我还不能完全理解我的中间方法语法

var viewModel = new propertyDetailData();
viewModel.properties = db.properties.Where(s => s.propertyId == id).Single();
viewModel.unitMixes = db.properties.Where(s => s.propertyId == id).Single().unitMixes;
提前感谢,, 约翰

您可以执行列表上的orderby。 您不需要获取列表,然后执行
.Single()
您可以搜索
等于
您的
委托的
元素
Single()

viewModel.unitMixes = db.properties.Where(s => s.propertyId == id)
                                   .Single().unitMixes
                                   .OrderBy(m => m.createDate)
                                   .ToList();
viewModel.properties = db.properties.Where(s => s.propertyId == id).Single();
viewModel.unitMixes = viewModel.properties.unitMixes.OrderBy(u => u.createDate);
viewModel.properties = db.properties.Single(s => s.propertyId == id);
viewModel.unitMixes = db.properties.Single(s => s.propertyId == id).unitMixes
                                       .OrderBy(m => m.createDate)
                                       .ToList();