我有一个IQueryable
这样的对象
var persons = from m in db.Persons
select m;
返回的字段为:name: String
,family: String
,cityID: Int
。我有另一个IQueryable
对象从另一个表中得到cityID: Int
和CityName: String
,如下所示:
var citys = from x in db.CitysInfo
select x;
现在我想要一个IQueryable
,name: String
,family: String
的{{1}}对象。我怎么能这样做?
答案 0 :(得分:4)
您可以将联接和项目用于匿名类:
var results = from p in db.Persons
join c in db.CitysInfo on p.cityID equals c.cityId
select new
{
name = p.name,
family = p.family,
CityName = c.CityName,
}