Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
C# 是否需要Linq to entities nullable int列?_C#_Entity Framework_Linq To Entities - Fatal编程技术网

C# 是否需要Linq to entities nullable int列?

C# 是否需要Linq to entities nullable int列?,c#,entity-framework,linq-to-entities,C#,Entity Framework,Linq To Entities,我试图在两个表之间进行左外部联接,但结果查询始终显示错误:“System.InvalidOperationException:'转换为值类型'System.Int32'失败,因为具体化的值为null。结果类型的泛型参数或查询必须使用可为null的类型。” 我的表实际上包含一个Id int列,但我的目标是将Id为“null”的条目列为业务仍然需要创建的条目。这个Id属性的值可以是0,这也很好,但是现在我不能用它做任何事情。这是我目前的查询: from items in

我试图在两个表之间进行左外部联接,但结果查询始终显示错误:“System.InvalidOperationException:'转换为值类型'System.Int32'失败,因为具体化的值为null。结果类型的泛型参数或查询必须使用可为null的类型。”

我的表实际上包含一个Id int列,但我的目标是将Id为“null”的条目列为业务仍然需要创建的条目。这个Id属性的值可以是0,这也很好,但是现在我不能用它做任何事情。这是我目前的查询:

from items in
                        (
                            from x in ctx.SAP_Shippeds select new { MaterialNumber = x.Material, MaterialDescription = x.MaterialDescription })
                            .Concat(from y in ctx.SAP_Ordereds select new { MaterialNumber = y.Material, MaterialDescription = y.MaterialDescription }
                        ).Distinct()
                        join pc in ctx.SAP_CrestronProductCategories on items.MaterialNumber equals pc.MaterialNumber into g
                        from col in g.DefaultIfEmpty()
                        select new ViewModelForProductCategory
                        {
                            Id = col.Id,
                            MaterialNumber = col.MaterialNumber,
                            CrestronLvl1Description = col.CrestronLvl1Description,
                            CrestronLvl2Description = col.CrestronLvl2Description,
                            CrestronLvl3Description = col.CrestronLvl3Description,
                            TigLvl1Description = col.TigLvl1Description,
                            TigLvl2Description = col.TigLvl2Description,
                            TigLvl3Description = col.TigLvl3Description
                        });
所以基本上我有一份订单和发票的清单。我想将这两个表的唯一(不同的)物料编号合并到一个表中,然后将它们合并到另一个表中,业务部门将为它们添加说明。 order或shipped表中存在但不在description表中的MaterialNumbers也应该出现(但随后id为NULL),这样我就可以清楚地表明业务部门仍然需要输入这些


任何人都可以提供帮助?

使用(int?)而不是(int),或者ViewModelForProductCategory类中有一个属性需要从int更改为int?viewmodel属性不是问题所在。问题是SAP_CrestronProductCategories的int属性与我得到的错误有关。这是一个自动编号列,我不能或想使其为空。您是否使用数据库工具检查数据库中是否有空值?没有空值,也不可能有空值,因为它是表的自动编号键。空值是由于外部联接而创建的,这是我想要的,如果需要,我愿意将空值转换为0。如果你不想要左外连接,那也很好。您正在创建一个新的ViewModelForProductCategory,当右侧为null时,col的所有值也为null。删除左侧外部联接(g.DefaultIfEmpty)将解决该问题。