private void InsertLinks(IEnumerable<string> urls)
{
EntityDataModelContext context = DataContext.GetDataContext();
foreach (string url in urls)
{
string url1 = url;
if (context.Links.Any(l => MatchUrlHash(l.UrlHash, url1)))
{
continue;
}
Link link = new Link
{
Url = url,
};
context.Links.AddObject(link);
}
context.SaveChanges();
}
private bool MatchUrlHash(long urlHash, string url)
{
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
byte[] encoded = Encoding.ASCII.GetBytes(url);
byte[] checksum = sha.ComputeHash(encoded);
long hash = BitConverter.ToInt64(checksum, 0);
return urlHash == hash;
}
如何將此查詢轉換爲仍能正常執行並且不會丟失任何NotSupportedException
的東西?LINQ To Entities以及如何使這個簡單的查詢工作
順便說一句,叫處置或更好地利用'using'語句的上下文實例。 – 2012-02-20 19:32:09