Concat
एसक्यूएल में UNION ALL
की LINQ बराबर है।
मैंने Union
और Concat
का उपयोग करने का तरीका दिखाने के लिए LINQPad में एक साधारण उदाहरण स्थापित किया है। यदि आपके पास LINQPad नहीं है, तो इसे प्राप्त करें।
इन सेट ऑपरेशंस के लिए अलग-अलग परिणाम देखने में सक्षम होने के लिए, डेटा के पहले और दूसरे सेटों में कम से कम कुछ ओवरलैप होना चाहिए। नीचे दिए गए उदाहरण में, दोनों सेटों में "नहीं" शब्द होता है।
LINQPad खोलें और भाषा ड्रॉप-डाउन को सी # स्टेटमेंट पर सेट करें। क्वेरी फलक में निम्न पेस्ट करें और इसे चलाने:
string[] jedi = { "These", "are", "not" };
string[] mindtrick = { "not", "the", "droids..." };
// Union of jedi with mindtrick
var union =
(from word in jedi select word).Union
(from word in mindtrick select word);
// Print each word in union
union.Dump("Union");
// Result: (Note that "not" only appears once)
// These are not the droids...
// Concat of jedi with mindtrick (equivalent of UNION ALL)
var unionAll =
(from word in jedi select word).Concat
(from word in mindtrick select word);
// Print each word in unionAll
unionAll.Dump("Concat");
// Result: (Note that "not" appears twice; once from each dataset)
// These are not not the droids...
// Note that union is the equivalent of .Concat.Distinct
var concatDistinct =
(from word in jedi select word).Concat
(from word in mindtrick select word).Distinct();
// Print each word in concatDistinct
concatDistinct.Dump("Concat.Distinct");
// Result: (same as Union; "not" only appears once)
// These are not the droids...
LINQPad में परिणाम इस प्रकार है:
स्रोत
2012-04-28 04:20:25
आप जॉन क्रोवेल्ल के जवाब को चिह्नित करना चाहिए के रूप में 'स्वीकार किए जाते हैं' – arviman