2012-12-03 24 views
7

मैं इस LINQ में चुनिंदाकरें

public List<EquipamentoNoDiscovery> GetEquipamentosNoDiscovery(int imID) 

var lista = (from ma in ctx.macaddress 
         join m in ctx.mac on 
         ma.address_mac equals m.mac_id into g1 
         from m in g1.DefaultIfEmpty() 

         join ml in ctx.mac_link on 
         m.mac_id equals ml.mac_id into g2 
         from ml in g2.DefaultIfEmpty() 

         join im in ctx.immobile on 
         ml.link_id equals im.immobile_id into g3 
         from im in g3.DefaultIfEmpty() 

         join en in ctx.enterprise on 
          im.enterprise_id equals en.enterprise_id into g4 
         from en in g4.DefaultIfEmpty() 

         join pl in ctx.port_link on 
         ma.address_id equals pl.address_id into g5 
         from pl in g5.DefaultIfEmpty() 

         join p in ctx.port on 
         new { pl.sw_id, pl.port_id } equals new { p.sw_id, p.port_id } 

         join s in ctx.switch_lan on 
         pl.sw_id equals s.sw_id into g6 
         from s in g6.DefaultIfEmpty() 
         where pl.address_id == imID 
         select new 
         { 
          Regiao = en.enterprise_u_name, 
          Predio = im.immobile_u_name, 
          Equipamento = m.host, 
          TipoPlaca = m.mac_type, 
          Mac = ma.address_mac, 
          Ip_ma = ma.address_ip, 
          Ip_m = m.ip_address, 
          Comunidade = s.sw_community, 
          IpSwitch = s.sw_ip, 
          PortaIndex = p.port_index, 
          PortaNome = p.port_name 
         }); 

      ObjectQuery oQuery = (ObjectQuery)lista; 
      string cmdSQL = oQuery.ToTraceString(); 

जब मैं कमांड oQuery.ToTraceString() का उपयोग, मैं देख सकता है "जहां pl.address_id == imID" बन गए हैं यह "कहां [विस्तार 6]। [address_id] = @p_ linq _0"। फिर मेरा चयन हमेशा खाली हो जाता है, अगर SQL कमांड में मैं मान @p_ linq _0 को किसी संख्या में बदलता हूं, तो यह ठीक काम करता है। कोई सुझाव, कृपया? धन्यवाद!

उत्तर

7

यह सिर्फ एक प्रश्न पैरामीटर है जो इस where से आता है।

where pl.address_id == imID 

आपका लॉग भी मूल्य जो कि पैरामीटर के लिए पारित किया गया है, जो imID का मान होना चाहिए दिखाना चाहिए। उस मान को जांचें - यह संभव है कि यह वह नहीं है जिसे आप उम्मीद करते हैं।

+0

डीबगिंग मोड में मैं देख सकता हूं कि आईएमआईडी की कीमत 2 की अपेक्षा की गई है लेकिन यह किसी भी तरह से काम नहीं करता है। केवल SQL कमांड में – Sah

+0

@Sah: आपके डेटाबेस में 'address_in' का प्रकार क्या है? –

+0

यह पीके, एफके, int, शून्य नहीं है – Sah