Join DocumentDB LINQ查询-不支持选择方法
应用程序:Join DocumentDB LINQ查询-不支持选择方法,join,lambda,azure-cosmosdb,Join,Lambda,Azure Cosmosdb,应用程序: .Net标准类库(包含一系列存储库) 最新版本 Azure宇宙数据库模拟器 示例文档结构: { “ProfileName”:“用户配置文件123”, “国家”:“英国”, “标签”:[{ “Id”:“686e4c9c-f1ab-40ce-8472-cc5d63597263”, “名称”:“标记1” }, { “Id”:“caa2c2a0-cc5b-42e3-9943-dcda776bdc20”, “名称”:“标记2” }], “主题”:[{ “Id”:“baa2c2a0-cc5
- .Net标准类库(包含一系列存储库)
- 最新版本
- Azure宇宙数据库模拟器
{
“ProfileName”:“用户配置文件123”,
“国家”:“英国”,
“标签”:[{
“Id”:“686e4c9c-f1ab-40ce-8472-cc5d63597263”,
“名称”:“标记1”
},
{
“Id”:“caa2c2a0-cc5b-42e3-9943-dcda776bdc20”,
“名称”:“标记2”
}],
“主题”:[{
“Id”:“baa2c2a0-cc5b-42e3-9943-dcda776bdc20”,
“名称”:“主题A”
},
{
“Id”:“aaa2c2a0-cc5b-42e3-9943-dcda776bdc30”,
“名称”:“主题B”
},
{
“Id”:“eaa2c2a0-cc5b-42e3-9943-dcda776bdc40”,
“名称”:“主题C”
}]
}
我需要什么?我希望能够使用LINQ表达式返回所有文档
在您的例子中,标记和主题是对象数组,如果使用以下linq代码,它将得到null
var q = from d in client.CreateDocumentQuery<Profile>(
UriFactory.CreateDocumentCollectionUri("database", "coll"))
where d.Country == "UK" && d.Tags.Contains(new Tag
{
Id = "686e4c9c-f1ab-40ce-8472-cc5d63597264"
}) && d.Topics.Contains(new Topic
{
Id = "baa2c2a0-cc5b-42e3-9943-dcda776bdc22"
})
select d;
请重试,然后获取Azure documentDb SDK不支持的内容
var q = from d in client.CreateDocumentQuery<Profile>(
UriFactory.CreateDocumentCollectionUri("database", "coll"))
where d.Country == "UK" && d.Tags.Contains(new Tag
{
Id = "686e4c9c-f1ab-40ce-8472-cc5d63597264"
},new CompareTag()) && d.Topics.Contains(new Topic
{
Id = "baa2c2a0-cc5b-42e3-9943-dcda776bdc22"
}, new CompareTopic())
select d;
用SDK查询
FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
var endpointUrl = "https://cosmosaccountName.documents.azure.com:443/";
var primaryKey = "VNMIT4ydeC.....";
var client = new DocumentClient(new Uri(endpointUrl), primaryKey);
var sql = "SELECT * FROM root WHERE (ARRAY_CONTAINS(root.Tags, {\"Id\":\"686e4c9c-f1ab-40ce-8472-cc5d63597263\"},true) AND ARRAY_CONTAINS(root.Topics, {\"Id\":\"baa2c2a0-cc5b-42e3-9943-dcda776bdc20\"},true) AND root.Country = \"UK\")";
var profileQuery = client.CreateDocumentQuery<Profile>(
UriFactory.CreateDocumentCollectionUri("dbname", "collectionName"),sql, queryOptions).AsDocumentQuery();
var profileList = new List<Profile>();
while (profileQuery.HasMoreResults)
{
profileList.AddRange(profileQuery.ExecuteNextAsync<Profile>().Result);
}
Topic.cs
public class Topic
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Tag
{
public string Id { get; set; }
public string Name { get; set; }
}
Tag.cs
public class Topic
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Tag
{
public string Id { get; set; }
public string Name { get; set; }
}
那么,您想要以下SQL查询的LINQ查询表示形式是什么:从概要文件中选择c,在c中加入ct。主题在c中加入l。标记中c.Country='UK'和ct.id='fa2e11e3-07aa-450a-8fc0-da3c738fec98'和l.id='260dadbc-d2de-457a-8d42-98799875b10f'
public class Tag
{
public string Id { get; set; }
public string Name { get; set; }
}