Linq ';System.Collections.Generic.List<;int>;。包含(int)和#x27;有一些无效的参数

Linq ';System.Collections.Generic.List<;int>;。包含(int)和#x27;有一些无效的参数,linq,entity-framework,entity,Linq,Entity Framework,Entity,Enity framework查询显示错误,但不知道原因。如果我试图获取主Id的列表 int PlantDemandId = 1; var result = (from c in context.tbl_PlantSupply where c.DemandId == PlantDemandId select c.Id).ToList(); c.

Enity framework查询显示错误,但不知道原因。如果我试图获取主Id的列表

            int PlantDemandId = 1;
            var result = (from c in context.tbl_PlantSupply
                          where c.DemandId == PlantDemandId
                          select c.Id).ToList();
c.Id是主键

当我使用c.DemandId时,它工作得很好

当我使用c.Id时,它在下面的查询中显示错误

            var result1 = (from c in context.tbl_NoOfPlantSupplied
                           join p in context.PlantationTypes on c.PlantationTypeId equals p.Id
                           join cl in context.Clones on c.CloneId equals cl.Id
                           where result.Contains(c.PlantSupplyId)

                           select new
                           {
                               PlantSupplyId = c.PlantSupplyId,
                               SourceOfSupplyId = c.SourceOfSupplyId,
                               PlantationTypeId = c.PlantSupplyId,
                               PlantationTypeName=p.Name,
                               CloneId = c.CloneId,
                               CloneName=cl.Name,
                               Supply = c.Supply
                           }).ToList();
其中result.Contains(c.PlantSupplyId):此行显示错误

    'System.Collections.Generic.List<int>.Contains(int)' has some invalid arguments
     convert from int? to int
“System.Collections.Generic.List.Contains(int)”具有一些无效参数
从int转换?整型

您不能比较int吗?和int.Use

c.PlantSupplyId.HasValue && result.Contains(c.PlantSupplyId.Value)

相反,

看起来PlantSupplyId具有空值。请检查tbl_NoofPlantProvidered是否有空值。我相信是的。这就是为什么错误要求您将可为null的int(int?)转换为int,因为您不能在contains()函数中传递null


如果可以在PlantSupplyId列中使用空值,那么您可以在查询中通过消除空值行来处理它。

它的c.PlantSupplyId.Value。。。价值的V是资本(智力帮助不显示这一点)。。谢谢亲爱的:)