dapper c# mssql带参数的select返回null。

问题描述 投票:0回答:1

在我的案例中,当我尝试使用参数时,Dapper返回null。

User user;
            using (var c = new SqlConnection(con.GetConnectionString()))
            {

                var sql = @$"SELECT 
                                tt_id as Id,
                                tt_imie AS Name, 
                                tt_nazwisko AS Surname, 
                                tt_login AS Login
                            FROM nteren_terenowi
                            WHERE tt_login = '@Login'
                                  AND tt_pin = @Pin
                                  AND tt_czy_aktywny = 1;";

                user = c.QueryFirstOrDefault<User>(sql, credentials.GetParam(), commandTimeout: 3000); //its null
            }

    public class UserIdentityMobile : IDynamicParameters
    {
        public string Login { get; set; }
        public string Pin { get; set; }

        public DynamicParameters GetParam()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            dictionary.Add("Login", this.Login);
            dictionary.Add("Pin", this.Pin);

            return new DynamicParameters(dictionary);
        }
    }

如果我在sql中传递params硬编码的用户不是null。谁能帮帮我:)?

c# sql-server dapper
1个回答
3
投票

我想 WHERE tt_login = '@Login' 应是 WHERE tt_login = @Login

© www.soinside.com 2019 - 2024. All rights reserved.