Results 1 to 4 of 4

Thread: [RESOLVED] LINQ Problem

Threaded View

  1. #1

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Resolved [RESOLVED] LINQ Problem

    I got a class object that holds some data: Customer, State, Sales, Date. I then call a database with a large collection of data and populate several thousand of these class objects.

    Next, using a little LINQ, I make two IEnumerable collections of these objects based on the date-range.

    Each of these, I use some more LINQ to Aggregate them into Groups by State and Customer. Thus, now I got two lists, each list has a unique identity based on State and Customer.

    How do I get a list of all items that are in List2 that don't have a matching entry in List1 (matching based on the State/Customer)? I cobbled together a way to do it but I suspect there's a far simpler solution. Also, looking over this code, can anything be simplified? This is my first time doing mass-LINQ manipulation of data objects. I usually don't get this detailed in it.

    Code is below for review.

    Code:
            Dim r1 = From so In Me Where so.DateInvoiced >= dteFrom1 AndAlso so.DateInvoiced <= dteTo1 Select so
            Dim r2 = From so In Me Where so.DateInvoiced >= dteFrom2 AndAlso so.DateInvoiced <= dteTo2 Select so
    
            Dim rUSA1 = From so In r1 Where Not so.Ship_State.Equals(String.Empty) Select so
            Dim rUSA2 = From so In r2 Where Not so.Ship_State.Equals(String.Empty) Select so
    
            Dim decGrandTotal1 As Decimal = Aggregate so In r1 Select so.Total Into Sum()
            Dim decGrandTotal2 As Decimal = Aggregate so In r2 Select so.Total Into Sum()
    
            Dim rStates1 = From so In rUSA1 Group so By so.Ship_State, so.CustomerCode Into Group Select Ship_State, CustomerCode, Total = Group.Sum(Function(so) so.Total), Percent = Group.Sum(Function(so) so.Total) / decGrandTotal1
            Dim rStates2 = From so In rUSA2 Group so By so.Ship_State, so.CustomerCode Into Group Select Ship_State, CustomerCode, Total = Group.Sum(Function(so) so.Total), Percent = Group.Sum(Function(so) so.Total) / decGrandTotal2
    
            'How do I get a list of all rStates2 items that don't have a matching rStates1 record?
            'Can any of the above code be simplified (such as the Total = Group.Sum(Function) parts)?
    Last edited by Jenner; Mar 23rd, 2011 at 09:59 AM.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width