1

I am very new into LINQ

I have following 2 queries:

var ticketStatus = from lookup in lookupDetails.AsEnumerable()
                   join ticket in ticketDetails
                       on lookup.LookupDetailID equals ticket.Status
                   select ticket;

var ticketSev = from lookupSev in lookupDetails.AsEnumerable()
                join ticket in ticketDetails
                    on lookupSev.LookupDetailID equals ticket.Status
                select ticket;

var finalTicket = ...

Now I want to merge ticketStatus and ticketSev into finalTicket. How can I achieve this task? I dont want to use Join.

Gabe
  • 84,912
  • 12
  • 139
  • 238
ghanshyam.mirani
  • 3,075
  • 11
  • 45
  • 85
  • 3
    Aren't those two queries exactly the same or am I missing something? – dtb Dec 15 '11 at 06:28
  • @dtb: The first query joins `lookup` against `ticket`, while the second one joins `lookupSev` against `ticket`. – Gabe Dec 15 '11 at 14:29

3 Answers3

3

Simple use this to Concatenate and remove duplicate

var finalTicket = ticketStatus.Union(ticketSev);   

To Simple concatenation and sort. Duplicates are preserved. use .Concat() on place of .Union()

To implement this in best way follow the following links:
How to: Combine and Compare String Collections (LINQ)
Merging two Collection<T>
Create a list from two object lists with linq

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
2
var finalTicket = ticketStatus.Union(ticketSev);   // remove duplicates
var finalTicket = ticketStatus.Concat(ticketSev);  // keep duplicates
Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
1

You didn't say how you want to merge them, so I'll assume you want the union of both sets (i.e. combining them and eliminating duplicates):

var finalTicket = ticketStatus.Union(ticketSev);

If you want to keep duplicates or know there won't be any, you can concatenate the sequences instead:

var finalTicket = ticketStatus.Concat(ticketSev);
Gabe
  • 84,912
  • 12
  • 139
  • 238