2011-04-06 7 views
6

मैं अपने कोड में SQL के लिए निम्न LINQ उपयोग करने के लिए कोशिश कर रहा हूँ में शामिल हों:LINQ मुद्दों

(from s in dc.Accounts 
    join purchases in dc.Transactions on s.AccID equals purchases.Account into pu 
    join pop in dc.POPTransactions on new { s.ID, syncNo } equals new {AccId = pop.AccountID, SyncNo = pop.SyncNo } into po 
    where s.AccID == ID && s.Customer == false 
    select new AccsandPurchase { acc = s, purchases = pu.ToList(), pop = po.ToList() })); 

दूसरे में शामिल होने लाइन (ऊपर पूरे क्वेरी में 3 लाइन) पर त्रुटि होता है - मैं का इस्तेमाल किया यह करने के लिए तो यह सिर्फ s.ID और pop.AccountID पर शामिल हो गए और कहा कि सही काम किया, लेकिन अब मैं एक और critieria (syncno) मैं निम्नलिखित त्रुटि मिलती है में शामिल होने की शुरुआत की:

"The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'"

कोई भी विचार? कुछ नोट्स:

1: 'परिवर्तनीय' सिंकनो 'एक लंबा है, जैसा डीबी (बिगिंट) में मान है। डीबी में मूल्य शून्य है इसलिए मैंने "लंबा" भी कोशिश की है? चर प्रकार के रूप में

2: AccsandPurchase, मैं बनाया एक कस्टम वर्ग है तो आप शायद अनुमान लगा सकते हैं के रूप में

धन्यवाद

उत्तर

16

उदा ही में शामिल होने कुंजी नाम निर्दिष्ट करने के लिए

join pop in dc.POPTransactions on new { Key1 = s.ID, Key2 = syncNo } equals new {Key1 = pop.AccountID, Key2 = pop.SyncNo } 
+0

सही काम करता है। बहुत धन्यवाद! – Chris

5

MSDN डॉक्स से:

Type inference on composite keys depends on the names of the properties in the keys, and the order in which they occur. If the properties in the source sequences do not have the same names, you must assign new names in the keys. For example, if the Orders table and OrderDetails table each used different names for their columns, you could create composite keys by assigning identical names in the anonymous types:

join...on new {Name = o.CustomerName, ID = o.CustID} equals 
    new {Name = d.CustName, ID = d.CustID } 

http://msdn.microsoft.com/en-us/library/bb907099.aspx

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

  • कोई संबंधित समस्या नहीं^_^