LINQ - Exclude items in one list from another

I have a problem I can't seem to solve.
I need a list of vendors that a customer does NOT have in their list.

using System.Linq;
using System.Linq.Expressions;

Example List Data to the classes below
------------
    LIST Supplier Class
    101 , SupplierName1
    102 , SupplierName2
    103 , SupplierName3
    104 , SupplierName4
    105 , SupplierName5

    LIST Customer Class for CustomerId = 9999
    9999 , CustomerName1 , supplierBase=(101 , SupplierName1)
    9999 , CustomerName1 , supplierBase=(104 , SupplierName4)
    9999 , CustomerName1 , supplierBase=(105 , SupplierName5)


public class Supplier
{
    public virtual int SupplierId;
    public virtual string SupplierName;
}

public class Customer
{
    public virtual int CustomerId ;
    public virtual string CustomerName;
    public virtual SupplierBase supplierBase { get; set; } << contains SupplierId and 
other info
}

I created a list of ALL vendors:
    var vListSupplier = (from suppliers in Session.Linq<Supplier>()
                         select suppliers).ToList();


I created a list for a SPECIFIC customer and the vendors they use:
    var vListCustomer = (from customers in Session.Linq<Customer>()
                         where customers.CustomerId = 9999
                         select customers).ToList();

I can easily get a list of VENDORS that that a specific customer uses:
    var oLst2 = (From a In vListSupplier
                 Join b In vListCustomer On a.SupplierId Equals 
b.supplierBase.SupplierId
                 Select a).ToList();

HEY ... it might seem easy to you ...
    but it took me a day to get this far. :)
Then it took me another day
    NOT to be able to figure-out a solution to the following.

I need a list of vendors that a customer does NOT have in their list.
(Not in the vListCustomer list.)

I just do not know what I am missing.  I have tried example
after example on the web but most of the examples show
the LISTs being compared as exactly the same.

I have used the LINQ "Except" function but that requires
the objects be identical in structure so it doesn't seem to help.

I hope the above was understandable.  Can you please help?

Thanks


0
Jennifer
3/21/2010 5:37:46 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

2 Replies
2258 Views

Similar Articles

[PageSpeed] 39

"Jennifer Mathews" <waltersjennifer@live.com> wrote in message 
news:%238yr50RyKHA.2012@TK2MSFTNGP04.phx.gbl...
> [...]
> I have used the LINQ "Except" function but that requires
> the objects be identical in structure so it doesn't seem to help.

   Why not? If I have understood correctly what you are doing, the objects 
in both lists should be identical in structure: On the one hand you have the 
list of all suppliers. On the other, you have the list of suppliers used by 
one customer. Both lists contain objects of tye "Supplier". So applying the 
Except function should provide the solution that you are seeking.

0
Alberto
3/21/2010 6:49:38 PM
"Alberto Poblacion" <earthling-quitaestoparacontestar@poblacion.org> wrote 
in message news:%2361kLdSyKHA.2436@TK2MSFTNGP04.phx.gbl...
> "Jennifer Mathews" <waltersjennifer@live.com> wrote in message 
> news:%238yr50RyKHA.2012@TK2MSFTNGP04.phx.gbl...
>> [...]
>> I have used the LINQ "Except" function but that requires
>> the objects be identical in structure so it doesn't seem to help.
>
>   Why not? If I have understood correctly what you are doing, the objects 
> in both lists should be identical in structure: On the one hand you have 
> the list of all suppliers. On the other, you have the list of suppliers 
> used by one customer. Both lists contain objects of tye "Supplier". So 
> applying the Except function should provide the solution that you are 
> seeking.

I think the problem is the 2 lists contain the same type of object but 
different instances. There are 2 solutions to this. You can override Equals 
(and GetHashCode) in the objects or you can create an IEqualityComparer and 
pass an instance of that into Except.

Michael 


0
Michael
3/22/2010 1:16:49 AM
Reply:

Similar Artilces:

Referencing Cells in Another Worksheet
I have a worksheet with contact names and numbers and some have a combination of both. I have a Landscape and a Portrait Version. I want to be able to make changes in only one and the other would automatically update. It worked when I first created it using "=", but for some reason, when I inserted some lines and deleted others, the cells stopped working. I tried to fix, but no luck. I've also tried changing both formats to General and number and neither worked. Please help.... thank you! ...

Help! clear deny permission on view address list
while in Exchange System Manager I was modifying the rights to an address book I created under "All Address Lists" to limit some users from seeing the contents of this list (by unchecking the "allow inheritable permissions from parent..."). I think i checked a "deny" permission for "View Address List" for Authenticated Users because now I'm unable to see this list in Outlook or under "All Address Lists" in Exchange System Manager. I know it's still there because if I attempt to create another address list w/ the same name I get...

Sent items problem
I have a problem with items that have been placed in folders. Once an item is placed in a folder and then replied to or forwarded the item does not show up in the sent items folder. Rather it puts the sent item into the same folder the original email was located. I would like to revert all sent items to the sent items folder... Ideas? Thanks in advance. Ryan Hi Ryan, In Outlook, Tools -> Options -> E-mail Options, there is an setting for Save copies of messages in Sent Items folder. Make sure this option is checked. Best Regards, Ryan M. Keith, BSCSE, MCSE Microso...

Select distinct with anonymous type return error when one value is null
Hi, How can i do this query with anonymous types; SELECT DISTINCT IdTable2, Name FROM Table1 WHERE idTable2 != null This query return error if the idTable2 is null: bindingSource1.DataSource=MyDataSet.Table1.Select(c=> new {Id=c.IdTable2, Nome=c.Name }.Distinct(); Any idea? Thanks ...

Add on Suggestions after every Item
Is there an easy way to have the POS suggest jewelry and shoes after the purchase (without editing every item in the register?) Thanks in advance... Scott Santorio Director of Operations ...

LINQ to XML - Performance
Hi, Can anyone tell me how the performance compares between working with xml documents in the normal way (i.e. with xpath and the System.Xml) and LINQ. Is it any quicker or slower? Are there are distinct benefits to the user (and not just advantages for the coder) to working with LINQ? The work i will be doing is creating an xml document out of segments from other xml documents, transforming the document (XSL) and then retrieving/amending/appending data to the document. Currentlly xml transformations in .net 2.0 are very slow and performance takes a real hit with complex transforms. ...

importing/editing inventory items/defining columns within item win
Is there a way for me to import old inventory lists generated in a spreadsheet, and make them into new items within my database in RMS small business manager?? i have a spreadsheet of over two thousand items, and I would not like to have to manually input them, instead I would like to assign a colum to a specific cell in the item window. I also would like to be able to edit large groups of items with one action, for example editing a supplier name for multple entries. Also, I am trying to define which columns I can see when I search for an Item, I want to be able to see the item numbe...

disabled control variable
I have encountered a problem where it was not possible to add control variables to a dialog because the controls on the 'Add Member Variable Wizard' dialog were disabled. This happened once before and 'miraculously' corrected itself after I had spent several days modifying and testing another part of the program. The problem reoccurred last night and I decided it was time to work this one through. This problem has been reported several times over the past few years with the most recent posting coming from Keith Murray (Oct 9, 2002). The reported solutions to this problem b...

How do I turn off List Manager?
Version: 2004 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I've read what I can online about turning off List Manager in Excel, but nothing I see applies to my situation. I clicked yes, when it suggested that I turn it on. My bad. Now, how do I reverse that decision? It should be intuitive, but it's not. Please give me some advice. I'm running 11.5.6 on Mac OS 10.6 (Snow Leopard). When active in the List you should have a List toolbar displayed. Click the List button on the bar & select 'Remove List Manager'. If the bar isn't displa...

Use Multi-Select List Box as Query Parameter
Is there a way to get the multiple selections from a list box into my query as the parameters? You need to use VBA. http://www.mvps.org/access/forms/frm0007.htm at "The Access Web" is an example, although personally I prefer using code more similar to http://www.mvps.org/access/reports/rpt0005.htm since it generates shorter criteria. (The first one generates a criteria like Field1 = Value1 Or Field1 = Value3 or Field1 = Value4, while the second one generates a criteria like Field1 In (Value1, Value2, Value3)) -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-...

mising item on transfear
Hi All I make on work sheet 330:Inventory Transfer and send from warehouse to store A. work sheet process successfully and I make issued from warehouse but when I go to store A I find worksheet is empty(without items). Is there any one face this problem before? Is there any way to adjust this problem? thanks for help -- MOHAMMED I. OWN THE BODY SHOP K.S.A +966557266607 Hi , It might be your items that you have put on WS:Style 330, that items are not found in your store (A). Check those barcodes in Store A, in Items If not found,try downloading the items to the store A ...

Recover Deleted Items #8
Good Day, I have just learnt how to recover deleted items from my own mailbox stored in Exchange 2000, this works well. I have additional mailboxes added to my MAPI profile but the Recover deleted items feature is not enabled for these mailboxes. Is there a way that I can recover deleted items for additional mailboxes without having to log on to my machine as the user/owner of these mailboxes? Thanks, Paul. Can this In news:umVrEHXLGHA.552@TK2MSFTNGP10.phx.gbl, Paul Johnson <pjohnson@domewood.plus.com> typed: > Good Day, > > I have just learnt how to recover delet...

Report that prints PO items
We need a report that prints all PO with thier respective Items. We pnly found the PO report that only display just the PO header line. Where in RMS reports is this option? check your gmail. "RicoTowers" <RicoTowers@discussions.microsoft.com> wrote in message news:935C72F9-BF40-47C2-9236-20150FA5C2F4@microsoft.com... > We need a report that prints all PO with thier respective Items. We pnly > found the PO report that only display just the PO header line. > > Where in RMS reports is this option? > Ramon. Modique un reporte, si necesita ayuda aviseme &...

Favourites Items in the Toolbar
I would like to see in the next version of Office the option of “Favourites” in the toolbar. Every month I find myself looking for spreadsheets that I previously used last month. These items are no longer in the handy list of last used spreadsheets and I find myself looking for them in the hierarchy of directories. When I use Internet Explorer I am able to add the list of frequently visited items to my Favourites button. I would like to see the same feature built into Excel (or any other Office Application) so I can quickly retrieve these files in the same manner. ----------------...

how to config Server for one user which has 2 mail address.
we have one NT4.0 + Exchange 5.5 Server "A" Email abc@xxx.com.cn ��and another windows2003 + exchange 2003 Server "B" abc@cn.xxx.com user name is same in A B��Mx record was be set ,question is how to config Exchange 2003 to receive down the mail to Server A , because of we need to replace A with B. thanks a lot. E2K3 setup guides you through common scenarios (like yours) pretty much holding your hand - on welcome screen tell it that you have existing E55 org and want to join it, then follow on-screen instructions. Having usable backup of Exchange databases and AD i...

How does one "turn a page" in an excel workbook?
Anyone know if there's a keyboard shortcut for "turning pages" in a workbook in excel? I find it very time consuming and wasteful having to use my mouse for this. thank you very much. If you mean change worksheets, it's Ctrl-PgDn, Ctrl-PgUp. -- Jim Rech Excel MVP "tgard75" <tgard75@discussions.microsoft.com> wrote in message news:F6A54143-C38D-4764-9A72-BA68F4C748FD@microsoft.com... | Anyone know if there's a keyboard shortcut for "turning pages" in a workbook | in excel? I find it very time consuming and wasteful having to use my mou...

Formula for look up in another sheet?
I can't figure out which function/formula to use. sheet1!A1 has a reference that gives a value of sheet2. sheet2!B1 has a text value "happy camper" I want sheet1!A2 to have a formula that gets the sheet name from sheet1!A1 (so "sheet2") and retrieves the value in cell B1 of that sheet, ie, "happy camper". So the result is sheet1!A2 shows a value of "happy camper". Easy, right? What's the formula for that? Thx! =INDIRECT("'"&A1&"'!B1") -- For everyone's benefit keep the discussion in the newsgroup...

item barcodes and sql query
This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C89274.4D47EC80 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, Customer forgot to set the right barcodes for the items they left it blank. Customer would like to print labels but since they did not specify the right barcode types in the item properties I guess it will not work. So is there a sql query that can do that? For example I would like to it to use upca for all items, since almost all of their products are upca's. Thank you. ------=_NextPart_000_0007_01C...

Severing links to list names when moving sheets between workbooks
When I move sheets to another spreadsheet, is there a way to automatically sever the links so that it doesnt keep asking about list names? Can anyone advise of direct me? Thanks,Roger Roger, see if this works for you. Sub RemoveLinks() Dim Link As Variant With ActiveWorkbook For Each Link In .LinkSources .BreakLink Name:=Link, Type:=xlLinkTypeExcelLinks Next End With End Sub -- jb "Roger on Excel" wrote: > When I move sheets to another spreadsheet, is there a way to automatically &g...

How to Color a Box on a Report when Change in one Field's Data
I want to have a box on a report change it's back color from one color to another and back again on every change in a field called "CollectionCode." The box is in the detail section. It is not in its own section for stylistic reasons. However, it is the first field listed in the sort. Thanks, Matt doyle60@aol.com wrote: >I want to have a box on a report change it's back color from one color >to another and back again on every change in a field called >"CollectionCode." > >The box is in the detail section. It is not in its own...

Exporting just one rule
Hi, How do I export just one rule? I have a very complex rule that I have to replicate to all users. Thanks. As far as I know, no. What you can do is this: - export all your rules to a file - delete all the rules but the one - export your rules (now only one) to another file - re-import your rules that you exported in Step 1 "Microsoft" <g2@bla.cl> wrote in message news:%23B%23VrJp0GHA.1256@TK2MSFTNGP04.phx.gbl... > Hi, > How do I export just one rule? > I have a very complex rule that I have to replicate to all users. ...

Language incompatibility and "upgrading" CRM from one lang to anot
We recently had a problem doing some work for a client because our CRM implementation is American English and theirs is International English. How can I 'upgrade' our CRM from American English to International English. Thanks Gill Opsis www.opsis.com.au Gill, Don't think you can. The language versions require the underlying servers to be installed with the indicated language as well. It's not as easy as just reinstalling the app. Matt Parks MVP - Microsoft CRM ---------------------------------------- ---------------------------------------- On Mon, 4 Apr 2005 18:39:...

EDITLABELS issue with list control
hi there i have a listview control with LVS_EDITLABELS style turned on everything works fine except for one thing: if the list is UNfocused, and i use the mouse to select the list to bring it back into focus, AND the mouse clicks on the currently selected item when doing this, it goes immediately into EDITLABELS mode (ie an edit control with the item label in it) i want to change this so it doesn;t go into EDITLABELS mode if the selection of the current item is purely to set the focus back to the list (try it in Windows Explorer, it doesn;t do it there) as an aside, i have a tree view con...

How to MoveFirst, MoveNext, MovePrevious, MoveLast in LinQ To XMl Please Help
I have the Next XML var xml = new XElement( "clients", new XElement("client", new XAttribute("id",1), new XElement( "name", "Luis"), new XElement( "country", "Portugal") ), new XElement("client", new XAttribute("id",2), n...

Movement of cursor within a drop down list
When we type a letter in the cell, the cursor should move to the word starting with that letter in the drop down list. How this can be done? If you are using a Data Valadation drop down try this. Sort your validation list and at the beginning of the A's enter a single A, do the same for the beginning of the B's and all the way through to the Z's. Click in the cell that has the drop down validation and type in the letter of the list you desire... say you type in an O. DO NOT hit enter... leave the cell in the edit mode (still selected) and now hit your down arrow. Should take...