2012-12-03 20 views
7

我有這樣的選擇在LINQ與一個奇怪的值@ p__linq__0選擇在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」成爲這個「WHERE [Extent6]。[address_id] = @p_ linq _0」。 然後,我的選擇總是返回空,如果在SQL命令中,我將值@p_ linq _0更改爲數字,它工作正常。 有什麼建議嗎? 謝謝!

回答

7

這只是一個來自這個where分支的查詢參數。

where pl.address_id == imID 

您的日誌還應該顯示爲該參數傳遞的值,該值應該是imID的值。檢查價值 - 這可能不是你所期望的。

+0

在調試模式我可以看到imid具有值2,但它不會以任何方式工作。僅在SQL命令中 – Sah

+0

@Sah:數據庫中「address_in」的類型是什麼? –

+0

這是PK,FK,int,非空 – Sah