我正在使用Dapper和C#来获取商店程序的结果。
表(TPTable
)以Pid
作为主键,Value
作为第二列和其他一些列的名称。
我有一个商店:select * from TPTable
。
当我调用QueryAsync<TPTableModel>
方法时,结果值Value Column的值总是与主键相同
在DB
中说Pid = 1,值= 2
Pid = 2,值= 568
结果将是{{Pid = 1,Value = 1},{Pid = 2,Value = 2}}的列表。
为什么我每次都会Value
等于PrimaryKey?
答案 0 :(得分:1)
这在本地工作正常:
[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; }
}
我很乐意调查,但非常感谢repro。
答案 1 :(得分:1)