2013-05-28 7 views
5

मैं कोई तिथि नहीं Linq उपयोग कर रहा हूँ निम्नलिखित रिपोर्टदो तालिकाओं

बनाने के लिए पर दो जहां का उपयोग कर शामिल होने के साथ LINQ का उपयोग कर रहा

 

#Users 
nid  pid  name 
1  1  name1 
2  1  name2 

#Transactions 
nid  tid  location dcode 
1  T1  L1   D1 
2  T1  L2   D1 
2  T2  L1   D1 
2  T2  L3   D1 

नीचे के रूप में दो तालिकाओं है रिपोर्ट में

 

    a) columns from users table where nid != pid 
    b) columns from transactions where tid == T2 and nid = results from a) 
    c) the combination can have only one top row in result 

nid  name  tid  Location 
2  name2  T2  L1 

the second record will not be present 
- 2  name2  T2  L3 

मैंने

var report = (from u in users where u.nid != u.pid 
         join t in transactions 
         where t.tid == "T2" 
         on u.nid equals t.nid 
         select new 
         { 
         // the report columns 
         }).Distinct().ToList(); 
में शामिल होने का उपयोग करके निम्नलिखित का प्रयास किया है

दूसरा 'जहां' एक त्रुटि

प्रदर्शित किया जाता है

(किसी भी सहायता

उत्तर

2

स्वैप छानने और आपकी क्वेरी के शामिल होने भागों के लिए धन्यवाद और अपने उदाहरण में t.tid या अन्य वांछित छानने खंड में tid का नाम बदलने के परिणामस्वरूप मेज पर करता है tid == "T1" के साथ लेनदेन है, लेकिन आप) T2 साथ फिल्टर करने के लिए प्रयास करें:

var report = (from u in users  
       join t in transactions 
       on u.nid equals t.tid  //<-- this line should precede 
       where t.tid == "T2"  //<-- this one 
       && u.nid != u.pid 
       select new 
       { 
        // the report columns 
       }).Distinct().ToList(); 

जुड़ें भागों अलग नहीं किया जा सकता है, तो आप where जब तक आपसमाप्त नहीं लिख सकते हैं on खंड के साथ 0।

+0

हाँ, त्रुटि गायब हो गई है, मैं इसे 8 मिनट के बाद उत्तर के रूप में चिह्नित करूंगा .. धन्यवाद – arvind

संबंधित मुद्दे