使用匿名类型-一个变量选择两个不同的查询 [英] Using anonymous types - one variable choose two different queries
本文介绍了使用匿名类型-一个变量选择两个不同的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对两个查询之一进行变量处理,但是有两个不同的表,并且出现错误无法确定条件表达式的类型,因为在System.Linq.IQueryable<WGamesTicket>
和System.Linq.IQueryable<AllGamesTicket>
I want to variable take one of two queries but there are two different tables and I have error "Type of conditional expression cannot be determined because there is no implicit conversion between System.Linq.IQueryable<WGamesTicket>
and System.Linq.IQueryable<AllGamesTicket>
var dsakj = (type == "mix") ?
(from el in objDC.WGamesTickets
where el.ticket.time == DTtemp
//&& el.typeOfGame == "mix"
select el)
:
(from el in objDC.AllGamesTickets
where el.ticket.time == DTtemp
//&& el.typeOfGame == "eng"
select el);
推荐答案
您必须转换为新的自定义类.例如,您要从两个不同的表中提取数据,但也许您想从每个表中收集ID和名称.因此,将您的代码更改为:
You'll have to cast to a new custom class. For example, you're pulling from two different tables, but maybe you want to collect the id and name from each. So change your code to:
var dsakj = (type == "mix") ?
(from el in objDC.WGamesTickets
where el.ticket.time == DTtemp
//&& el.typeOfGame == "mix"
select new myCustomObject()
{
id = el.id,
name = el.name,
})
:
(from el in objDC.AllGamesTickets
where el.ticket.time == DTtemp
//&& el.typeOfGame == "eng"
select new myCustomObject()
{
id = el.id,
name = el.name,
});
这篇关于使用匿名类型-一个变量选择两个不同的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文