Linq查询 [英] Linq Query

查看:87
本文介绍了Linq查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有两个列表:


A = {ID,Name} = {(Null,John),( Null,Mary),(Null,Andrew),(Null,

Peter)}


B = {ID,Name} = {(1,John ),(2,Robert),(3,Angela),(4,Andrew)}


我想找到A中哪些项目不存在于B中:


1.将项目添加到B并使用函数GetID()中的ID。 B

将成为:


B = {ID,Name} = {(1,John),(2,Robert),(3,Angela) ,(4,

Andrew),(231,Mary),(45,Peter)}


2.然后更新A列表,或者创建一个新的(C),获得创建的

项目:


C = {ID,Name} = {(231,Mary),(45,彼得)}


如何使用LINQ执行此操作?


我一直在尝试加入,但使用的内容为not equals ;但

它不起作用。


我想我可能需要分三步完成:


1.在B中获取C中不存在的项目;

2.在C中插入这些项目;

3.从C再次获取这些项目以获取创建的ID这是

通讯员的名字。


有人可以帮我解决这个问题吗?


谢谢,

Miguel

Hello,

I have two Lists:

A = {ID, Name} = { (Null, John), (Null, Mary), (Null, Andrew), (Null,
Peter) }

B = {ID, Name} = { (1, John), (2, Robert), (3, Angela), (4, Andrew) }

I want to find which items in A do not exist in B then:

1. Add the items to B and using an ID from the function GetID(). B
would become:

B = {ID, Name} = { (1, John), (2, Robert), (3, Angela), (4,
Andrew), (231, Mary), (45, Peter) }

2. Then update the A list, or create a new one (C), to get the created
items:

C = {ID, Name} = { (231, Mary), (45, Peter) }

How can I do this with LINQ?

I have been trying a join but with the something as "not equals" but
it does not work.

I think I might need to do this in 3 steps:

1. Get items in B that do not exist in C;
2. Insert those items in C;
3. Get those items again from C to get the created ID''s with the
correspondent names.

Could someone help me out with this?

Thanks,
Miguel


推荐答案

7月4日,2:38 * pm,shapper< ; mdmo ... @ gmail.comwrote:
On Jul 4, 2:38*pm, shapper <mdmo...@gmail.comwrote:

我有两个列表:
I have two Lists:



在内存中,或者你真的想在SQL中这样做吗?内存中的一些

解决方案可能无法通过LINQ to SQL工作。


您可以使用Except运算符找出A中的哪些元素不是
B中的
,必要时传入IEqualityComparer中的项目。


(Marc:如果你正在读这个 - 我们应该写一个

ProjectionEqualityComparer和ProjectionComparer一样?

而不是ThenBy我们也可以用And组合

IEqualityComparers ...... )


Jon

In memory, or are you actually trying to do this in SQL? Some
solutions for in memory may not work via LINQ to SQL.

You can use the Except operator to find out which elements in A aren''t
in B, passing in an IEqualityComparer for the items if necessary.

(Marc: if you''re reading this - should we write a
ProjectionEqualityComparer along the same lines as ProjectionComparer?
Instead of "ThenBy" we could also have "And" to combine
IEqualityComparers...)

Jon


Marc:如果你正在读这个...


听起来合理;可能想要一个或同样......或者可能是VB。与

" AndAlso" /" OrElse" ; -p


OT:回购访问权限(必须从网站获得r259);我可以很容易地在我的最后得到
...


Marc
Marc: if you''re reading this...

Sounds reasonable; might want an "Or" as well... or maybe go "VB" with
"AndAlso"/"OrElse" ;-p

OT: repo access playing up (had to get r259 from site); could easily be
at my end, though...

Marc


OT:

现在似乎已修复;一定是我......


Marc
OT:
Seems fixed now; must have been me...

Marc


这篇关于Linq查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆