我有一個方法返回Iqueryable結果,但結果是基於if else條件,如果條件滿足那麼我將使用「AssetDetails」類對象,否則爲「UserandClientdetails」對象。 下面是代碼:運行時Iqueryable的類型
private IQueryable<?> GetAssetDetails(ShareViewModel item)
{
...
if (type == "Video")
{
if (type == "Video")
{
return from meta in my.Assets().OfType<Model.Video>()
join content in my.Contents() on meta.ContentId equals content.ID
join channel in my.Channels() on content.ChannelId equals channel.ID
where meta.ID == item.ID
select new AssetDetails
{
ContentTitle = content.Title,
ChannelName = channel.ChannelName,
...
};
}
else
{ return from meta in my.Assets().OfType<Model.Client>()
join country in db.Countries on meta.ResellerCountry equals country.ID
where meta.ID == item.ID
select new UserAndClientDetails
{
Name = meta.ResellerName,
UserName = meta.ResellerEmail,
..
};}
那麼如何在運行時決定Iqueyable的類型在這裏?
將實體框架排除在圖片之外。如果你有一條採用兩條路徑返回完全不同的東西的方法,你會怎麼做? – Dismissile
您可以嘗試簡單地返回'IQueryable'而不是泛型'IQueryable <>'。 –