Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在LINQ中选择一个奇怪的值@p\u LINQ\u 0_Sql Server_Entity Framework_C# 4.0_Linq To Sql - Fatal编程技术网

Sql server 在LINQ中选择一个奇怪的值@p\u LINQ\u 0

Sql server 在LINQ中选择一个奇怪的值@p\u LINQ\u 0,sql-server,entity-framework,c#-4.0,linq-to-sql,Sql Server,Entity Framework,C# 4.0,Linq To Sql,我在林克有这个选择 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

我在林克有这个选择

 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();
公共列表GetEquipmentOSNodeDiscovery(int imID)
var lista=(来自ctx.macaddress中的ma
在上的ctx.mac中加入m
ma.address_mac等于进入g1的m.mac_id
从g1.DefaultIfEmpty()中的m开始
在上的ctx.mac_链接中加入ml
m、 mac_id等于g2中的ml.mac_id
从g2.DefaultIfEmpty()中的ml
在ctx中加入im。在
ml.link_id等于im.im.immobile_id进入g3
来自g3.DefaultIfEmpty()中的im
在ctx.enterprise上加入en
im.enterprise\u id等于en.enterprise\u id进入g4
来自g4.DefaultIfEmpty()中的en
在上的ctx.port_链接中加入pl
ma.address\u id等于g5中的pl.address\u id
来自g5.DefaultIfEmpty()中的pl
在上的ctx.port中加入p
新的{pl.sw_id,pl.port_id}等于新的{p.sw_id,p.port_id}
加入ctx。打开局域网
pl.sw_id等于g6中的s.sw_id
来自g6.DefaultIfEmpty()中的s
其中pl.address_id==imID
选择新的
{
Regiao=企业名称,
Predio=im.不动的名称,
Equipmento=m.host,
TipoPlaca=m.mac_类型,
Mac=ma.address\u Mac,
Ip\u ma=ma.address\u Ip,
Ip\u m=m.Ip\u地址,
Comunidade=s.sw_社区,
IpSwitch=s.sw\U ip,
PortaIndex=p.port_索引,
PortaNome=p.port\u名称
});
ObjectQuery oQuery=(ObjectQuery)lista;
string cmdSQL=oQuery.ToTraceString();
当我使用命令oQuery.ToTraceString()时,我可以看到“where pl.address\u id==imID”变成了“where[Extent6].[address\u id]=@p\u linq\u 0”。 然后,我的select始终返回空,如果在SQL命令中我将@p_linq_0的值更改为一个数字,则效果良好。 有什么建议吗?
谢谢

这只是一个查询参数,它来自于
其中的
子句

where pl.address_id == imID

日志还应显示为该参数传递的值,该值应为
imID
的值。检查该值-它可能不是您预期的值。

在调试模式下,我可以看到imID的值为2,与预期值相同,但它无法正常工作。仅在SQL中command@Sah:数据库中的
地址的类型是什么?它是PK、FK、int,而不是null@Sah:那么它真的应该很好用。使用值为2的参数的查询的工作方式应该与将2直接放入查询中的方式相同,我希望……我将“where im.enterprise\u id==imID”更改为“im.enterprise\u id==2”。但它仍然不起作用=/