1

I have these classes:

public class RegionResult
{
    public string Region { get; 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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I got entity framework 4.1 installed and I cant use lamda expressions for some reason.. only string parameter avalible
Seems you have some class that extends objectquery
@Lasse Edsvik: Its an extension method. You have to include the namespace System.Data.Entity. See this walkthrough on EF 4.1: blogs.msdn.com/b/adonet/archive/2011/01/31/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.