对于我存储在DocumentDb数据库中的以下JSON对象,我创建了一个SELECT查询,并使用Query Explorer在Azure Portal上对其进行了测试 . 我在门户网站上得到的结果是正确的 .
然后我在我的代码中使用相同的确切查询 - 使用DocumentDb客户端,结果不完全正确 .
这是存储在DocumentDb中的完整JSON文档
{
id: 987456,
name: "Jerry Buss Family Trust",
sportsTeams: [
{
id: 123,
type: "Professional Basketball Team",
team: "Los Angeles Lakers",
coach: "Byron Scott",
players: [
{
id: 2,
name: "Brandon Bass",
position: "Forward"
},
{
id: 24,
name: "Kobe Bryant",
position: "Forward-Guard"
},
{
id: 4,
name: "Ryan Kelly",
position: "Forward"
}
]
},
{
id: 345,
type: "Professional Hockey Team"
team: "Los Angeles Kings",
coach: "Darryl Sutter",
players: [
{
id: 15,
name: "Andy Andreoff",
position: "Forward"
},
{
id: 27,
name: "Alec Martinez",
position: "Defenseman"
},
{
id: 32,
name: "Jonathan Quick",
position: "Goalie"
}
]
}
]
}
我试图只获得“Jerry Buss Family Trust”文件下的运动队 . 这是我的SQL:
SELECT c.id as teamId, c.name as teamName, c.players
FROM a JOIN c in a.sportsTeams
WHERE a.id = "987456"
当我在Azure门户查询资源管理器上运行时,我得到了我想要的主要文档中的id和名称以及所有玩家的数组 .
但是,当我在我的代码中使用此查询时,我得到了主要记录和player数组中正确的项目数,但每个数组项都有NULL值 . 所以我得到这样的东西:
{
id: 123,
name: "Los Angeles Lakers"
players: [
{
id: 0
name: NULL,
position: NULL
},
// etc. IMPORTANT: I do get the CORRECT number of sub-documents that correspond to players.
// Also note that the shape of the sub document is correct.
// The issue is that the data is missing!
]
}
执行READ查询的代码是:
public async Task<IEnumerable<T>> ReadQuery<T>(string collectionId, SqlQuerySpec sql)
{
var collectionLink = UriFactory.CreateDocumentCollectionUri(_dbName, collectionId);
var result = _client.CreateDocumentQuery<T>(collectionLink, query, null).ToList();
return result;
}
这段代码运行后,我正在检查结果,就像我说的那样,我确实得到了正确的主文档数据 . 我也得到了正确的子文档数量/形状,但是子文档中没有任何数据 .
知道是什么导致了这个问题吗?