选择目的地中尚不存在的所有内容 [英] Select All that do not already exist in destination
问题描述
我有一组简单的数组,有点像..为简洁起见而缩短的结构.基本上,它是带有附加字段(一种字典)的身份列表.
I have a simple set of arrays, kind of like this .. structure shortened for brevity and such. Basically it is a list of identities with an additional field (a sort of dictionary).
[
{
"Id" : 1,
"Requirement" : {
"Value" : "2", "Name" : "Orders"
}
},
{
"Id" : 2,
"Requirement" : {
"Value" : "4", "Name" : "Orders"
}
},
{
"Id" : 3,
"Requirement" : {
"Value" : "6", "Name" : "Orders"
}
},
{
"Id" : 4,
"Requirement" : {
"Value" : "8", "Name" : "Orders"
}
},
]
我需要不断检查此数组的另一个值,并提取满足条件的项(例如,用户"具有任意值Orders
,该值是整数.每次Orders
更新,我想从Orders
大于或等于Requirement值的数组中取出所有项目,但不提取它们已经拥有的值)
I need to be constantly checking another value against this array, and pulling in the items that are satisfied (for instance, the 'user' has an arbitrary value of Orders
that is an integer. Each time Orders
updates, I want to get all items out of the array where Orders
is greater than or equal to the Requirement value, but without pulling in values they already have)
因此,这将按以下方式工作...
User
具有1个Order
. (什么都没发生)
User
具有2个Order
. (运行用户的更新操作时,将拉出Id 1)
User
然后达到4 Order
. (将ID 2拉入,但Id 1已经存在,因此将其跳过)
So then, this would work as follows ...
User
has 1 Order
. (Nothing Happens)
User
has 2 Order
. (Id 1 is pulled when the user's update operation runs)
User
then achieves 4 Order
. (Id 2 is pulled in, but Id 1 already exists, so it is skipped)
是否有使用LINQ查询实现这一目标的简单方法?我没有奢侈的东西来存储最后检查"的值.我目前无法修改数据结构.
Is there a simplistic way to achieve this with a LINQ query? I don't have the luxury of storing the 'last checked' value. The data structure is not one I can modify at this point in time.
推荐答案
Orders.Where(o => o.Requirement.Value > requirment).Except(processedOrders);
首先选择符合要求的Orders
,然后使用Except
删除已处理的订单.
First select the Orders
that meet the requirement, then using the Except
remove the orders that have already been processed.
这篇关于选择目的地中尚不存在的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!