0
私は2つの表を一緒に結合しようとしていますが、列の1つはNULL可能intであり、もう1つはintです。私はNULL可能intにint型の列をキャストしようとしたが、エラーにlinqで異なるフィールドタイプの2つのテーブルを結合することは可能ですか?
を得る「無効な匿名型のメンバ宣言子。匿名型メンバーは、メンバーの割り当て、単純名またはメンバのアクセスを宣言する必要があります。」 MSDNから
TableA
int? SupplierId
string SupplierName
TableB
int SupplierId
string Name
string result;
using (var db = Dal.MyEntities(false))
{
result = db.TableA
.Select(c => new { SupplierId = c.SupplierID, SupplierName = c.SupplierName })
.Union(db.TableB.Select(g => new { (int?)g.SupplierId, SupplierName = g.Name }))
.Where(c => c.SupplierId == supplierId)
.Select(c => c.SupplierName)
.FirstOrDefault();
}