0

In VS2008, I think it is EF1.0, this works just fine.

string queryString = @"SELECT VALUE USERS FROM ProjectDBEntities.Users AS User 
            INNER JOIN ProjectDBEntities.Favorites AS F ON F.FavUserId = User.UserId
            WHERE F.UserId = " + 3 + " ORDER BY F.CreateDate DESC ";

        System.Data.Objects.ObjectQuery<User> usersQuery =
                new System.Data.Objects.ObjectQuery<User>(queryString, context).Include("Detail");

        //int count = usersQuery.Count();
        foreach (User result in usersQuery)
            Console.WriteLine("User Name: {0}", result.UserName);

Same code in VS2010 EF4 it crashes on the foreach loop with the following error:

The result type of the query is neither an EntityType nor a CollectionType with an entity element type. An Include path can only be specified for a query with one of these result types.

Picflight
  • 3,832
  • 13
  • 61
  • 90
  • Do you require an ESQL solution? This would be trivial with L2E. – Craig Stuntz May 14 '10 at 13:19
  • Craig, how would it done with L2E? – Picflight May 14 '10 at 15:20
  • As per my post [here](http://social.msdn.microsoft.com/Forums/en-US/732cbb72-2ca0-45c3-8702-b30c3c077aa8/entitydatasource-issue?forum=adodotnetentityframework&prof=required) it seems you don't need to specify the `Include` if you're already using a custom `Select`. (So try removing the Include). – PeterX Jul 31 '14 at 10:00

1 Answers1

2
var q = from u in ProjectDBEntities.Users
        from f in u.Favorites
        where f.User.Id == 3
        orderby f.CreateDate desc;

I'm making some presumptions about your entity model/property names since you don't show it, but this should give you the general idea.

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273