开发者

Nested classes using entity framework and linq

I have these classes:

public class RegionResult
{
    public string Region { ge开发者_如何学Ct; set; }
    public List<Unicorn> Unicorns { get; set; }
}

public class Unicorn
{
    public string Name { get; set; }
    public string Color { get; set; }
    public Dictionary<string, string> Parameters { get; set; }
}

And I would assign data to a List from my datacontext. "Flat" query would look like:

SELECT * FROM Regions R 
JOIN Unicorns U ON R.X = U.X
LEFT JOIN Parameters P ON U.X = P.X

I would like to have it grouped by region, and for each region populate with unicorns, and parameters if not null. How would that query look like?

List<RegionResult> regions = (from a in (_entites.Regions).AsEnumerable().GroupBy(...)
.select new... a = a.Unicorn.Name..  new .ToDictionary(key, value)?

Thanks in advance

/Lasse


If i understand you right, you just want to load the Regions with associated Unicorns and Parameters.

You dont have to group, just load the regions and include the related entities (This is for EF 4.1):

List<RegionResult> regions = 
     _entites.Regions.Include(r => r.Unicorns.Select(u => u.Parameters);

But i don't think, that you can map a Dictionary Type with Entity Framework.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜