我目前正在开发一个使用美国县级数据的小项目。我没有问题对数据进行 Seq.orderBy
排序,但是由于查询表达式中存在 sortBy
,我希望结果也能被排序。然而实际情况并非如此。
type SysData = SqlDataConnection<"Data Source=ROME\SQLEXPRESS;Initial Catalog=SysData;Integrated Security=True">
type County = { State : string; SSA : string }
let counties =
let db = SysData.GetDataContext()
query {
for c in db.CountyMatrix do
sortBy c.Countyssa
select { State = c.State; SSA = c.Countyssa }
distinct
}
现在,我正在执行以上操作,但我的结果看起来如下:
...
{State = "OR";
SSA = "38030";}
{State = "GA";
SSA = "11630";}
{State = "WA";
SSA = "50130";}
{State = "MN";
SSA = "24740";}
{State = "KY";
SSA = "18030";}
{State = "MO";
SSA = "26970";}
{State = "DC";
SSA = "09000";}
...
查询发送到我的本地SQL Server实例时,在IntelliTrace中显示如下:
USE [SysData];
GO
SELECT DISTINCT [t0].[state] AS [Item1], [t0].[countyssa] AS [Item2]
FROM [dbo].[CountyMatrix] AS [t0]
请注意缺少
ORDER BY
,我原本期望它会出现,因为查询表达式中有sortBy c.Countyssa
。你有什么想法,为什么我无法从
counties
中获得排序数据? 我的目标是尽可能简洁地展示给我的雇主作为一个小例子。提前感谢!
order by
,因此结果将是无序的。 - Pரதீப்distinct
吗?或者在表达式结束后使用|> Seq.distinct
是更好的选择? - Duncan Hillfor c in db.CountyMatrix do let c = { State = c.State; SSA = c.Countyssa } distinct sortBy c.SSA select c
?我的F#水平不足,不知道是否正确… - jessehouwing