2015-08-22 4 views
6

में शामिल होने के लिए कॉल में असफलता विफल रही है मैंने विभिन्न स्टैक ओवरफ्लो उत्तर को देखा है, लेकिन मुझे linq के साथ शामिल होने का तरीका नहीं दिख रहा है।लिंक क्वेरी प्रश्न

2 टेबल

var query = from tips in TblTips 
      where tips.Id == 30 
      join files in TblFiles on tips.Id equals files.Group 
      select new { tips, files }; 

त्रुटि:

Type inference failed in the call to Join 

अब tips.Id एक पूर्णांक है, जबकि files.Group एक varchar

मैं .Value

करने का प्रयास किया है
tips.id.Value  --> the word Value not working (most recent linqpad) 

(int)files.Group --> it doesn't like that ... 

उत्तर

6

समस्या यह है कि आप नहीं कर सकते ओटी तालिका कॉलम मानों में शामिल हों उसी प्रकार की नहीं!

Convert.ToInt32(column) should work in linqpad and your c# application just fine. 

(मैं कोष्ठक में लिपटे और एक ToList() जोड़ा)

यह आप के लिए काम करना चाहिए अगर समूह स्ट्रिंग और आईडी है पूर्णांक

var query = (from tips in TblTips 
      where tips.Id == 30 
      join files in TblFiles on tips.Id equals Convert.ToInt32(files.Group) 
      select new { tips, files }).ToList(); 

अद्यतन है:

प्रति ओपी, मैं उससे सहमत हूं कि इसे अन्य मान को स्ट्रिंग

में परिवर्तित करना चाहिए
var query = (from tips in TblTips 
      where tips.Id == 30 
      join files in TblFiles on tips.Id.ToString() equals files.Group 
      select new { tips, files }).ToList(); 
+1

मुझे लगता है कि यह वास्तव में 'टिप्स' करने के लिए सुरक्षित होगा। आईडी। टॉस्ट्रिंग() फाइलों के बराबर होती है। समूह'' 'फाइलें। समूह' एक पूर्णांक के अलावा कुछ और हो सकती है। – kmc059000

+0

ठीक है, यह काम करता है, मैंने Int32.Parse करने का प्रयास किया और इससे मुझे एक अलग त्रुटि मिली। धन्यवाद! –

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