does not contain a definition for 'Include'

4 posts, 1 answers
  1. Michael
    Michael avatar
    29 posts
    Member since:
    Nov 2010

    Posted 20 Nov 2010 Link to this post

    I port MSSQL "Music Store" database to PostgreSQL database for testing MVC2. Now for query database I use Open Acess ORM. For selected code :

    namespace MyMVC.Controllers
    {
        public class StoreController : Controller
        {
            MvcMusicStoreModel storeDB = new MvcMusicStoreModel(); 
      
      
            //
            // GET: /Store/Browse
            public ActionResult Browse(string genre)
            {
                // Retrive Genre and its Associated Albums from database
      
                // ---> HERE IS ERROR!!!
                var genreModel = storeDB.Genres.Include("Albums")
                    .Single(g => g.Name == genre);
                // <--- HERE IS ERROR!!!
      
      
                var viewModel = new StoreBrowseViewModel
                {
                    Genre = genreModel,
                    Albums = genreModel.Albums.ToLIst()
                };
      
                return View(viewModel);
            }

    I got this error :
    Error 1 'System.Linq.IQueryable<MyMVC.Genre>' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable<MyMVC.Genre>' could be found (are you missing a using directive or an assembly reference?) C:\Users\Michael\Documents\Visual Studio 2010\Projects\MyMVC\MyMVC\Controllers\StoreController.cs 37 45 MyMVC


    Any help?

    Michael

    p.s. If anyone ned Create script for PostgreSQL Music Store, make replay here.
  2. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 22 Nov 2010 Link to this post

    Hello Michael,

    Unfortunately we do not provide support for the Include extension method in our LINQ implementation, but we have it in our to-do list. We will add it to product in the future.
    In fact you could use our Fetch Optimization API to control the amount of data that is fetched during the execution of the queries. Helpful information regarding the API can be found under the following help section as well as in the following blog post.
    You should slightly modify the logic within the Browse method in order to achieve the desired goal:

    FetchStrategy fetchStrategy = new FetchStrategy();
    fetchStrategy.LoadWith<Genre>(g => g.Albums);
    storeDB.FetchStrategy = fetchStrategy;
     
    var genreModel = storeDB.Genres.Where(g => g.Name == genre).ToList().Select(x => new { Genre = x.Name, Albums = x.Albums }).Single();

    I hope that you find the provided information useful.

    Regards,
    Damyan Bogoev
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  3. DevCraft banner
  4. Michael
    Michael avatar
    29 posts
    Member since:
    Nov 2010

    Posted 23 Nov 2010 Link to this post

    Somehow I managed to fix the previous problem. It appears that because the parent-child relationships OA ORM, however pulled the child table, so include was not necessary!

    But your post and solution help with this code (album is in midle of tables Genre and Artist) :
    public ActionResult Index() 
        var albums = storeDB.Albums 
            .Include("Genre").Include("Artist"
            .ToList(); 
       
        return View(albums); 
    }

    Thanks a lot Damyan for solution.

    Michael
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 23 Nov 2010 Link to this post

    Hello Michael,

    I am glad to see that you managed to resolve this issue.
    If any other questions arise please contact us back.

    Sincerely yours,
    Damyan Bogoev
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Back to Top