This project is read-only.

Compilation error in Browse.cshtml file

Sep 23, 2012 at 11:16 AM

I am trying to implement MvcMusicStore using,

MS SQL Server 2008 professional Edition instead of Compact Edition.

Linq to Sql class instead of the default (as given in the tutorial).

First i created a Database named MvcMusicStore and execute the MvcMusicStore-Create.sql script. All the tables and associated data created successfully. In the model section to create model class i used Linq to Sql class template and drag and drop all the tables in the design window which created all associated classes and functions. The files inside the model folder are,

MvcMusicStore.dbml, MvcMusicStore.dbml.layout and MvcMusicStore.designer.cs

and it automatically created a connection string inside web.config as

    <add name="MvcMusicStoreConnectionString" connectionString="Data Source=AREFIN-SAMI;Initial Catalog=MvcMusicStore;Integrated Security=True"
      providerName="System.Data.SqlClient" />

And it was working as usual. Now inside the Browse action in the StoreControler i coded like,
 public ActionResult Browse( string genre)
            var genreModel = mdc.Genres.Include("Albums")
                .Single(g => g.Name == genre);
            return View(genreModel);
But, it shows an error:
Error 1 'System.Data.Linq.Table<MvcMusicStore.Models.Genre>' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Data.Linq.Table<MvcMusicStore.Models.Genre>' could be found (are you missing a using directive or an assembly reference?) H:\MvcMusicStore\MvcMusicStore\MvcMusicStore\Controllers\StoreController.cs 27 41 MvcMusicStore
though i used using system.Data.Linq;Using.Data.SqlClient;
The code inside the corresponding View Browse.cshtml:
@model MvcMusicStore.Models.Genre
    ViewBag.Title = "Browse Albums";

<h2>Genre : @Model.Name</h2>
@foreach(var album in Model.Albums)
also shows an error:

Browse.cshtml(7,2): error CS1579: foreach statement cannot operate on variables of type 'System.Data.Linq.EntitySet`1<MvcMusicStore.Models.Album>' because 'System.Data.Linq.EntitySet`1<MvcMusicStore.Models.Album>' does not contain a public definition for 'GetEnumerator'
Now i couldn't find what's the problem. Could you please help me.
Thank You. 
Sep 23, 2012 at 6:59 PM

Yup, i got the solution. There was missing of an assembly reference. I just added an assembly reference in the web.config file. i.e.,

<add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
That's it.