How to query Entities in Entity Framework 4

Posted by Picflight on Stack Overflow See other posts from Stack Overflow or by Picflight
Published on 2010-05-13T20:05:02Z Indexed on 2010/05/14 17:34 UTC
Read the original article Hit count: 622

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.

© Stack Overflow or respective owner

Related posts about entity-framework-4

Related posts about objectquery