I have these LINQ queries :
var type1 = (from ftr in db.TB_FTR
join mst in db.TB_MST on ftr.MST_ID equals mst.MST_ID
join trf in db.TYPE_ID on mst.TYPE_ID equals trf.ID
where ftr.CITY == city && ftr.COUNTY == county
select new MyType { City = ftr.CITY, County = ftr.COUNTY Type = trf.TYPE }
).OrderBy(i => i.City);
var type2 = type1.GroupBy(i => new { i.City, i.County, i.Type })
.Select(group => new { Name = group.Key, MyCount = group.Count() })
.OrderBy(x => x.Name).ThenByDescending(x => x.MyCount)
.GroupBy(g => new { g.Name.City, g.Name.County })
.Select(g => g.Select(g2 =>
new { Name = new { g.Key.City, g.Key.County, g2.Name.Type }, g2.MyCount })).Take(1000).ToList();
As you see the 2nd query returns an anonymous type. But I want to use these queries in a method. So I can't return anonymous type. How can I make type2 as a non-anonymous type?
I have prepared two objects for that :
public class MyType
{
public string City { get; set; }
public string County { get; set; }
public string Type { get; set; }
}
public class ProcessedType
{
public MyType Name {get; set;}
public int MyCount {get; set;}
}
But I couldn't use them properly because I probably misplaced them in the query. Can you help me so that I can make the second query return a defined object? Thanks.