//I need to deifne productQuery here
if (test == true)
{
var productQuery = ordersRepository.ProductIn; //it returns IQueryable<ProductIn> type
}
else
{
var productQuery = ordersRepository.ProductOut; //it returns IQueryable<ProductOut> type
}
如何定义 productQuery 变量?
谢谢!
[编辑]
dynamic productType;
if (test == true)
{
productType = ordersRepository.ProductIn; //it returns IQueryable<ProductIn> type
}
else
{
productType = ordersRepository.ProductOut; //it returns IQueryable<ProductOut> type
}
var productQuery = productType as IQueryable<ProductIn>;
if (productQuery == null)
{
productQuery = productType as IQueryable<ProductIn>;
}
我这样做是正确的吗?