gpt4 book ai didi

c# - 帮助 Linq 查询

转载 作者:行者123 更新时间:2023-11-30 13:51:05 25 4
gpt4 key购买 nike

我正在编写一个 linq 查询,但遇到了麻烦,所以我想知道是否有人可以提供帮助。这是一些背景知识:

我没有设计数据库,因此无法更改结构。所以我有主要的“游戏”表,它有一个主要的产品代码,这个表中的外键是 GameData 表中的 GameDataID,它包含发布日期、发布者等信息。然后我有 GameFormat 表,它包含每种格式的游戏产品代码,例如Mac、Windows 等,GameDataID 又是一个外键。见下文。

Game

GameID PK
MainGameProductCode
MainGameTitle
GameDataID FK

GameData

GameDataID PK
GameReleaseDate
GameReleasedBy

GameFormat

GameFormatID PK
GameDataID FK
GameFormatProductcode

因此,当收到销售报告时,有些报告仅包含“GameFormatProductCode”作为产品标识符。因此,我需要从“GameFormatProductCode”中检索主游戏表中的“GameID”。

到目前为止,我已经编写了 linq 查询以从 GameFormat 表中检索 GameFormatProductcode,但是我不确定如何从主游戏表中检索 GameID。

private Int64 GetGameID(string gameFormatProductCode)
{
ModelCtn ctn = new ModelCtn();
Game game = null;
GameFormat gf = null;

gf = (from t in ctn.GameFormat
where t.GameFormatProductcode == gameFormatProductCode
select t).FirstOrDefault();

// Need to find GameID from Game table and return it.

return gf;

}

有哪位 linq 专家愿意为我指出正确的方向吗? Linq 的新手所以要温柔:)

最佳答案

您可以从GameFormat 表中获取GameDataID 并使用它来查询Game

private Int64 GetGameID(string gameFormatProductCode)
{
ModelCtn ctn = new ModelCtn();
Game game = null;
GameFormat gf = null;

gf = (from t in ctn.GameFormat
where t.GameFormatProductcode == gameFormatProductCode
select t).FirstOrDefault();

// Need to find GameID from Game table and return it.
var gID = (from t in ctn.Game
where t.GameDataID == gf.GameDataID
select t.GameID).FirstOrDefault();

return gID;

}

关于c# - 帮助 Linq 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5077009/

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