Silverlight - LinqToEntities - How Do I Return Anonymous Types

I'm not sure if I'm going at this the right way. I have a Silverlight app and using Entity Framework for a lot of it. I have Two Entities mapped to my database: Header and Details. I want to submit a left outter join to get all headers and details counts - even if the header record has no detail record. Here is the Linq Query I want to run from the Client:

var query =
      from head in storeContext.Headers
      join detail in storeContext.Details
      on head.HeadId equals details.HeadId
      into group
      select new 
      {
        Desc = head.Description,
        MyCount = group.Count()
      };

Since this is Silverlight, I need to build my query, then submit it to the server with the storeContext.Load<T>() method from my Domain Service (Context on the client). Because this method is expecting a type, I don't know how to structure the call to return an anonymous type as I am dong above?

Am I doing this all wrong? Should I be using an Invoke method for something like this? If so, how and where do I define the type I want to return?

Is someone could point me in the right direction I would really appriciate it.

Thanks... Scott

Answers


You can't return an anonymous type. They are, by necessity, local to the current scope.

Your query looks correct, but you will need to return a named type:

var query =
      from head in storeContext.Headers
      join detail in storeContext.Details
      on head.HeadId equals details.HeadId
      into group
      select new MyHelper // SPECIFY A CLASS HERE
      {
        Desc = head.Description,
        MyCount = group.Count()
      };

Your query method will need to return an IEnumerable<MyHelper>:

public IEnumerable<MyHelper> GetInfo()
{
    var query ...

    return query;
}

Need Your Help

How do I make a list of items where each item has associated information in Android?

java android

How do I make a list of items where each item has associated information in Android?

Simple DbSet<TEntity>.Find() Call Taking Forever

c# .net entity-framework linq-to-entities

I am getting terrible performance from a DbSet.Find() call. My code looks like this: