更改IQueryable对象中的数据

时间:2012-01-30 17:01:16

标签: c# linq iqueryable

我有一个IQueryable这样的对象

var persons = from m in db.Persons
              select m;

返回的字段为:name: Stringfamily: StringcityID: Int。我有另一个IQueryable对象从另一个表中得到cityID: IntCityName: String,如下所示:

var citys = from x in db.CitysInfo
            select x;

现在我想要一个IQueryablename: Stringfamily: String的{​​{1}}对象。我怎么能这样做?

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,
              }