This is a migrated thread and some comments may be shown as answers.

does not contain a definition for 'Include'

3 Answers 622 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 2
Michael asked on 20 Nov 2010, 04:15 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 22 Nov 2010, 06:00 PM
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.
0
Michael
Top achievements
Rank 2
answered on 23 Nov 2010, 01:23 PM
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
0
Damyan Bogoev
Telerik team
answered on 23 Nov 2010, 07:47 PM
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.
Tags
Data Access Free Edition
Asked by
Michael
Top achievements
Rank 2
Answers by
Damyan Bogoev
Telerik team
Michael
Top achievements
Rank 2
Share this question
or