Guid[]:如何从 Cosmos DB 查询和获取详细信息?

时间:2021-02-08 09:43:37

标签: c# .net azure-cosmosdb

我正在使用 Azure CosmosDB。我有以下 GetProgramsByStudentIDAsync 方法,该方法需要获取与 studentID 关联的所有程序(注意 studentID 的类型为 Guid)。

using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Threading.Tasks;

     public async Task<ProgramContainer> GetProgramsByStudentIDAsync(Guid[] studentIds)
                {  
    
    var db = Client.GetDatabase(databaseId);
    
    var programContainer = db.GetContainer(containerId);     
                  
                using FeedIterator<ProgramContainer> feedIterator = programContainer.GetItemLinqQueryable<ProgramContainer>()
                    .Where(x => studentIds.Contains(x.StudentId)).ToFeedIterator(); //Giving me error at studentIds.Contains  Please find the error details below: 

CS1929:Guid[] 不包含“包含”的定义,最佳扩展方法重载需要接收器类型

ProgramContainer 类供参考:

public class ProgramContainer
    {
    public string ProgramName{ get; set; }
    public string ProgramCode { get; set; }
    public Guid StudentId { get; set; }
    public bool IsActive { get; set; }
    }

请协助。提前致谢!!!

1 个答案:

答案 0 :(得分:0)

尝试显式转换为 guid

using FeedIterator<ProgramContainer> feedIterator = 
programContainer.GetItemLinqQueryable<ProgramContainer>()
                .Where(x => studentIds.Contains((Guid)x.StudentId)).ToFeedIterator();