Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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中合并两个具有不同字段类型的表?_C#_Linq - Fatal编程技术网

C# 是否可以在linq中合并两个具有不同字段类型的表?

C# 是否可以在linq中合并两个具有不同字段类型的表?,c#,linq,C#,Linq,我尝试将两个表合并在一起,但其中一列是可为null的int,另一列是int。我尝试将int列强制转换为可为null的int,但出现了错误 无效的匿名类型成员声明符。匿名类型成员必须使用成员分配、简单名称或成员访问权限声明 发件人: 必须为正在初始化的属性提供名称 表情 在您的情况下,您应该为要强制转换为Nullable int type的表达式提供属性 result = db.TableA .Select(c => new { SupplierId

我尝试将两个表合并在一起,但其中一列是可为null的int,另一列是int。我尝试将int列强制转换为可为null的int,但出现了错误

无效的匿名类型成员声明符。匿名类型成员必须使用成员分配、简单名称或成员访问权限声明

发件人:

必须为正在初始化的属性提供名称 表情

在您的情况下,您应该为要强制转换为
Nullable int type的表达式提供属性

    result = db.TableA
                .Select(c => new { SupplierId = c.SupplierID, SupplierName = c.SupplierName })
                .Union(db.TableB.Select(g => new { SupplierId = (int?)g.SupplierId, SupplierName = g.Name }))
                .Where(c => c.SupplierId == supplierId)
                .Select(c => c.SupplierName)
                .FirstOrDefault();
发件人:

必须为正在初始化的属性提供名称 表情

在您的情况下,您应该为要强制转换为
Nullable int type的表达式提供属性

    result = db.TableA
                .Select(c => new { SupplierId = c.SupplierID, SupplierName = c.SupplierName })
                .Union(db.TableB.Select(g => new { SupplierId = (int?)g.SupplierId, SupplierName = g.Name }))
                .Where(c => c.SupplierId == supplierId)
                .Select(c => c.SupplierName)
                .FirstOrDefault();
    result = db.TableA
                .Select(c => new { SupplierId = c.SupplierID, SupplierName = c.SupplierName })
                .Union(db.TableB.Select(g => new { SupplierId = (int?)g.SupplierId, SupplierName = g.Name }))
                .Where(c => c.SupplierId == supplierId)
                .Select(c => c.SupplierName)
                .FirstOrDefault();