SqlFunctions.Checksum如何获取可查询的校验和 [英] SqlFunctions.Checksum how to get checksum for queryable
问题描述
我正在试图弄清楚如何让这个sql equivelant:
I'm trying to figure out how to get this sql equivelant:
select checksum_agg(checksum(*)) from Foo
来自linq SqlFunctions。只要我知道列,我就能轻松获得一列的校验和。但是,我不会知道列名。所以我可以这样做:
From linq SqlFunctions. I'm able to easily get the checksum for one column, so long as I know the column. However, I won't know column names. So I can do something like:
SqlFunctions.ChecksumAggregate(Foo.Select(x => x.Id))
但这只是校验和一列,我必须知道列名。有没有办法像SQL语句一样校验集合?或者在不知道列名的情况下一次将校验和作为一列?
But that is only the checksum of one column, and I have to know the column name. Is there a way to checksum the collection like the SQL statement? Or to get the checksum a column at a time without knowing the column name?
推荐答案
您可以使用 ChecksumAggregate 方法。
就像这样:
You can use ChecksumAggregate method for this.
It's like this :
using (AdventureWorksEntities AWEntities = new AdventureWorksEntities())
{
// SqlFunctions.ChecksumAggregate is executed in the database.
decimal? checkSum = SqlFunctions.ChecksumAggregate(
from o in AWEntities.SalesOrderHeaders
select o.SalesOrderID);
Console.WriteLine(checkSum);
}
欲了解更多信息,请查看:
http://msdn.microsoft.com/en-us/library /vstudio/dd456858(v=vs.100).aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/vstudio/dd487151(v = VS.100)的.aspx [ ^ ]
我希望这会对你有所帮助。
For more info check this :
http://msdn.microsoft.com/en-us/library/vstudio/dd456858(v=vs.100).aspx[^]
http://msdn.microsoft.com/en-us/library/vstudio/dd487151(v=vs.100).aspx[^]
I hope this will help to you.
这篇关于SqlFunctions.Checksum如何获取可查询的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!