相关疑难解决方法(0)

如何使用LINQ从DataTable获取不同的,有序的名称列表?

我有DataTable一个Name专栏.我想生成按字母顺序排列的唯一名称的集合.以下查询忽略order by子句.

var names =
    (from DataRow dr in dataTable.Rows
    orderby (string)dr["Name"]
    select (string)dr["Name"]).Distinct();
Run Code Online (Sandbox Code Playgroud)

为什么不orderby加强执行?

c# linq .net-3.5

97
推荐指数
4
解决办法
2万
查看次数

LINQ - 如何保存我的(复杂)结果?

我有LINQ查询,它是以零碎的方式构建的,如下所示:

var initialQuery = from item in MyContext where xxx == yyy select item;    
var furtherQuery = from item in initialQuery where bla == foo select new { some stuff };

// more code here...

// eventually:
var yetAnotherQuery = (from item in furtherQuery ...)
                      .OrderBy(my_condition);

// As far as I know, the following query should still maintain the order of the previous one
// see: https://stackoverflow.com/questions/911942/are-subqueries-in-linqtosql-guaranteed-to-be-in-the-same-order-as-their-parent

var stillAnotherQuery = (from item in yetAnotherQuery
                         select item.data_I_care_about)
                         .Distinct();

// And finally... …
Run Code Online (Sandbox Code Playgroud)

linq linq-to-entities

5
推荐指数
1
解决办法
647
查看次数

标签 统计

linq ×2

.net-3.5 ×1

c# ×1

linq-to-entities ×1