gpt4 book ai didi

c# - Linq SELECT 与 ExecuteQuery

转载 作者:太空狗 更新时间:2023-10-29 22:32:51 25 4
gpt4 key购买 nike

我得到错误:

The type 'System.Int32[]' must declare a default (parameterless) constructor in order to be constructed during mapping.

代码:

var gamePlayRecord = db.ExecuteQuery<int[]>("SELECT UserID, IPID, GameID FROM ArcadeGames WHERE ID = " + gamePlayRecordID).Single();
var userID = gamePlayRecord[0];
var ipID = gamePlayRecord[1];
var gameID = gamePlayRecord[2];

我知道这是错误的,但是有人可以告诉我如何在不需要创建新对象的情况下正确地做到这一点吗?

最佳答案

这个查询的结果不是int[]而是一行数字。

不好的解决方案:对每个数字使用:

int userID = db.ExecuteQuery<int>("SELECT UserID FROM ArcadeGames WHERE ID = " + gamePlayRecordID).Single();
int ipID = db.ExecuteQuery<int>("SELECT IPID FROM ArcadeGames WHERE ID = " + gamePlayRecordID).Single();
int gameID db.ExecuteQuery<int>("SELECT GameID FROM ArcadeGames WHERE ID = " + gamePlayRecordID).Single();

或者创建sql查询

db.ExecuteQuery<int>(@"
SELECT UserID FROM ArcadeGames WHERE ID = {0}
UNION ALL
SELECT IPID FROM ArcadeGames WHERE ID = {0}
UNION ALL
SELECT GameID FROM ArcadeGames WHERE ID = {0}",
gamePlayRecordID).ToList();

或者创建类...

关于c# - Linq SELECT 与 ExecuteQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17614545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com