数据库列值的 Dapper 错误值
Dapper wrong value for data base Column Value
我在 C# 中使用 Dapper 从存储过程中获取结果。
Table (TPTable
) 将 Pid
作为主键,将 Value
作为第二列和其他一些列的名称。
我有一家商店:select * from TPTable
.
当我调用 QueryAsync<TPTableModel>
方法时,结果是值列的值始终与主键相同
假设在数据库中
Pid = 1,值 = 2
Pid = 2,值 = 568
结果将是 {{Pid=1,Value=1},{Pid=2,Value=2}} 的列表。
为什么我每次都会得到 Value
等于 PrimaryKey?
这在本地工作正常:
[Fact]
public async void SO35470588_WrongValuePidValue()
{
// nuke, rebuild, and populate the table
try { connection.Execute("drop table TPTable"); } catch { }
connection.Execute(@"
create table TPTable (Pid int not null primary key identity(1,1), Value int not null);
insert TPTable (Value) values (2), (568)");
// fetch the data using the query in the question, then force to a dictionary
var rows = (await connection.QueryAsync<TPTable>("select * from TPTable"))
.ToDictionary(x => x.Pid);
// check the number of rows
rows.Count.IsEqualTo(2);
// check row 1
var row = rows[1];
row.Pid.IsEqualTo(1);
row.Value.IsEqualTo(2);
// check row 2
row = rows[2];
row.Pid.IsEqualTo(2);
row.Value.IsEqualTo(568);
}
public class TPTable
{
public int Pid { get; set; }
public int Value { get; set; }
}
我很乐意进行调查,但非常感谢您提供重现。
我发现了问题。不配Dapper。我正在重现一个小项目,我发现商店有一个内部连接,带有 sql 用户定义的类型。这种类型有一个名为 Value 的 Column,它具有主键的值。当我在商店中使用 select * 调用 Dapper 时,它将填充用户定义类型的值。
我在 C# 中使用 Dapper 从存储过程中获取结果。
Table (TPTable
) 将 Pid
作为主键,将 Value
作为第二列和其他一些列的名称。
我有一家商店:select * from TPTable
.
当我调用 QueryAsync<TPTableModel>
方法时,结果是值列的值始终与主键相同
假设在数据库中
Pid = 1,值 = 2
Pid = 2,值 = 568
结果将是 {{Pid=1,Value=1},{Pid=2,Value=2}} 的列表。
为什么我每次都会得到 Value
等于 PrimaryKey?
这在本地工作正常:
[Fact]
public async void SO35470588_WrongValuePidValue()
{
// nuke, rebuild, and populate the table
try { connection.Execute("drop table TPTable"); } catch { }
connection.Execute(@"
create table TPTable (Pid int not null primary key identity(1,1), Value int not null);
insert TPTable (Value) values (2), (568)");
// fetch the data using the query in the question, then force to a dictionary
var rows = (await connection.QueryAsync<TPTable>("select * from TPTable"))
.ToDictionary(x => x.Pid);
// check the number of rows
rows.Count.IsEqualTo(2);
// check row 1
var row = rows[1];
row.Pid.IsEqualTo(1);
row.Value.IsEqualTo(2);
// check row 2
row = rows[2];
row.Pid.IsEqualTo(2);
row.Value.IsEqualTo(568);
}
public class TPTable
{
public int Pid { get; set; }
public int Value { get; set; }
}
我很乐意进行调查,但非常感谢您提供重现。
我发现了问题。不配Dapper。我正在重现一个小项目,我发现商店有一个内部连接,带有 sql 用户定义的类型。这种类型有一个名为 Value 的 Column,它具有主键的值。当我在商店中使用 select * 调用 Dapper 时,它将填充用户定义类型的值。