0
我有兩個查詢返回相同的IQueryable
viewmodel。IQueryable Union with ViewModel不起作用
這是我第一次查詢:
var tempAfter = (from operation in _br_WarehouseOperation_GetAll.GetAll()
select new CardexSummaryViewModel
{
SumFirstImport = 0,
SumFirstExport = 0,
SumExport = g.Where(t => exportTypes == t.operation.TransactionTypeId).Sum(t => t.operationDetail.Quantity * t.operationDetail.UnitOfMeasure.ConversionFactor),
SumImport = g.Where(t => importTypes.Contains(t.operation.TransactionTypeId)).Sum(t => t.operationDetail.Quantity * t.operationDetail.UnitOfMeasure.ConversionFactor),
WarehouseGoodsId = warehouseGoods.WarehouseGoodsId,
SumPriceFirstImport = 0,
SumPriceFirstExport = 0,
SumPriceExport = g.Where(t => isPricing && exportTypes == t.operation.TransactionTypeId).Sum(t => t.operationDetail.WarehouseTransactionOperationPricings.Sum(it => it.TotalPrice)),
SumPriceImport = g.Where(t => isPricing && importTypes.Contains(t.operation.TransactionTypeId)).Sum(t => t.operationDetail.WarehouseTransactionOperationPricings.Sum(it => it.TotalPrice)),
});
,這是第二個查詢:
var tempBefore = (from operation in _br_WarehouseOperation_GetAll.GetAll()
select new CardexSummaryViewModel
{
SumFirstImport = g.Where(t => importTypes.Contains(t.operation.TransactionTypeId)).Sum(t => t.operationDetail.Quantity * t.operationDetail.UnitOfMeasure.ConversionFactor),
SumFirstExport = g.Where(t => exportTypes == t.operation.TransactionTypeId).Sum(t => t.operationDetail.Quantity * t.operationDetail.UnitOfMeasure.ConversionFactor),
SumExport = 0,
SumImport = 0,
WarehouseGoodsId = warehouseGoods.WarehouseGoodsId,
SumPriceFirstImport = g.Where(t => isPricing && importTypes.Contains(t.operation.TransactionTypeId))
.Sum(t => t.operationDetail.WarehouseTransactionOperationPricings.Sum(it => it.TotalPrice)),
SumPriceFirstExport = g.Where(t => isPricing && exportTypes == t.operation.TransactionTypeId)
.Sum(t => t.operationDetail.WarehouseTransactionOperationPricings.Sum(it => it.TotalPrice)),
SumPriceExport = 0,
SumPriceImport = 0,
});
我想聯盟這兩個查詢到一個數據庫中調用這樣的:
tempAfter = tempBefore.Union(tempAfter);
cardexSummery = tempAfter.ToList();
但它不起作用並重復行。
我想知道是否有人能告訴我我失去了什麼東西。謝謝
顯然它看起來像是在兩個對象中有不相交的數據集。通過不相交,我的意思是所有的財產的不同值被明確設定。如果是這種情況,'union'運算符將總是爲一個'WarehouseGoodsId'返回兩行,並且這兩行不重複,如果這意味着重複。 –
@SayanPal感謝您的評論。你是對的。我再次檢查了我的代碼,並意識到在我的viewModel中有一個計算類型屬性,可以由其他人計算其值。這是聯合爲WarehouseGoodsId返回兩行的原因 – RezaTorabi