Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 子列表中带有linq的cosmosdb where子句_C#_Linq_Azure Cosmosdb - Fatal编程技术网

C# 子列表中带有linq的cosmosdb where子句

C# 子列表中带有linq的cosmosdb where子句,c#,linq,azure-cosmosdb,C#,Linq,Azure Cosmosdb,我的根数据有几个子集合,我需要对其中的2个子集合执行where子句,示例: { "id": "000092224369_0030", .... "orderData": { ... "request_secondary": { "_type": "request_secondary", "secondary_requests": [{ "secondary_descr

我的根数据有几个子集合,我需要对其中的2个子集合执行where子句,示例:

   {
        "id": "000092224369_0030",
  ....
        "orderData": {
          ...
          "request_secondary": {
            "_type": "request_secondary",
            "secondary_requests": [{
"secondary_description":"do something" }]
          },
          "partnership": {
            "contacts": [
              {
                "role": "AG",
                "first_name": "LIEBENS Eric",
                "last_name": null,
                "_type": "contact",
                "email": "eric.liebens@gmail.com",
                "tel1": "0495-543905",
                "tel2": null,
                "vat": null
              },
              {
                "role": "ZO",
                "first_name": "Coralie",
                "last_name": "Demeyere",
                "_type": "contact",
                "email": "coralie.demeyere@ores.net",
                "tel1": "069/256533",
                "tel2": null,
                "vat": null
              },
              {
                "role": "ZR",
                "first_name": "GASBARRO Gianni",
                "last_name": null,
                "_type": "contact",
                "email": null,
                "tel1": "0495-385479-0",
                "tel2": null,
                "vat": "BE0474281005"
              }
            ],
    ...
在这里,我需要做一个查询,返回任何次要描述等于文本的记录,或者带有该文本的姓名的联系人。 它应该转换为sql,用于以下内容:

SELECT c.id from c
join x  in c.orderData.request_secondary
join y in c.orderData.partnership.contacts
where x.secondary_description ='sometin' or y.first_name= 'sometin'
我尝试过这个解决方案:

它在一个子集上效果很好,但我不知道如何才能在多个精选集上使用它。。。 在林克有什么办法可以做到这一点吗?
谢谢

根据您的描述,我认为您的SQL需要稍微调整一下

SELECT c.id from c
join x  in c.orderData.request_secondary.secondary_requests
join y in c.orderData.partnership.contacts
where x.secondary_description ='something' or y.first_name= 'something'
但是,结果中会有重复的数据。因此,我还建议您采用我在线程中回答的存储过程:

但是,我认为您仍然需要解决客户端上结果集的重复数据


希望对您有所帮助。

谢谢您的回答,虽然我理解您的意思,但有没有办法在Linq中实现我的查询?只是为了一般知识。抱歉耽搁了,疯狂的日子:我觉得这是一种奇怪的方式,所以我试了一下。实际上它似乎不起作用,我这样做:var test=sut.CreateQuery.SelectManyx=>x.Data.Attachments.Where s=>s.FileName==something | | x.Data.SecondaryRequest.SecondaryRequests.Where c=>c.SecondaryDescription==something;我得到一个错误运算符| |不能应用于“Ienumable”和“Ienumable”类型的操作数。没有拿我之前展示过的东西,但应该是一样的。。。我错过了什么?
function sample() {
    var collection = getContext().getCollection();
    var isAccepted = collection.queryDocuments(
        collection.getSelfLink(),
        'SELECT * FROM root r',
        function (err, feed, options) {
            if (err) throw err;
            if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
            else {
                var returnResult = [];
                for(var i = 0;i<feed.length;i++){
                    var isContinue = true;
                    var array1 = feed[i].orderData.request_secondary.secondary_requests;
                    var array2 = feed[i].orderData.partnership.contacts;
                    for(var j = 0;i<array1.length;j++){
                        if(array1[j].secondary_description == 'something'){
                            returnResult.push(feed[i]);
                            isContinue=false;
                            break;
                        }
                    }
                    if(isContinue){
                        for(var k = 0;i<array2.length;k++){
                            if(array2[j].first_name == 'something'){
                                returnResult.push(feed[i]);
                                break;
                            }
                        }
                    }    
                }
                getContext().getResponse().setBody(returnResult);
            }
        });

    if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
client.CreateDocumentQuery().SelectMany((x) => 
x.orderData.requestSecondary.secondaryRequests.Where(
    s=>s.secondaryDescription == "something" 
) ||
x.orderData.partnership.contacts.Where(
    c=>c.firstName == "something" 
)