我需要執行此SQL命令(Management Studio中正常工作):LinqToSql和HASHBYTES
select * from Users where Login = 'test' and PasswordHash = HashBytes('SHA1', 'test')
我寫這個C#linqtosql:
var user = db.ExecuteQuery<User>("select * from Users where Login = {0} and PasswordHash = HashBytes('SHA1', {1})", loginTextBox.Text.Trim(), passwordPasswordBox.Password).SingleOrDefault();
,但它永遠不會奏效!
有人可以幫我嗎?
謝謝!
這是DataContext的日誌:
select * from Users where Login = @p0 and PasswordHash = HashBytes('SHA1', @p1)
-- @p0: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [test]
-- @p1: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [test]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
回報總是空 – 2010-12-16 19:35:58
不論答案是什麼,我會將此轉換爲參數化查詢,否則你會把自己暴露給SQL注入攻擊。 – 2010-12-16 19:55:40
我不這麼認爲,因爲ExecuteQuery將任何{x}轉換爲@ p1,@ p2等... – 2010-12-16 19:59:55