1
我想你应该知道mvcmusicstore.codeplex.com上的在线MvcMusicStore应用程序教程。我正在使用MS SQl Server 2008专业版开发此项目,而不是使用MVC3的精简版。我用链接到Sql类作为模型类。它照常工作。但是,该视图内的代码文件Browse.cshtml视图(.cshtml)文件中的编译错误
@model MvcMusicStore.Models.Genre
@{
ViewBag.Title = "Browse";
}
<h2>Genre : @Model.Name</h2>
<ul>
@foreach(var album in @Model.Albums)
{
<li>@album.Title</li>
}
</ul>
生成编译错误消息作为,
Browse.cshtml(7,2):错误CS1579:foreach语句不能类型的变量操作' System.Data.Linq.EntitySet 1<MvcMusicStore.Models.Album>' because 'System.Data.Linq.EntitySet
1'不包含'GetEnumerator'的公共定义
所以,你可以给我一个解决方案来摆脱它。谢谢。 此外,体裁类
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Genres")]
public partial class Genre : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _GenreId;
private string _Name;
private string _Description;
private EntitySet<Album> _Albums;
...
Album类,
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Albums")]
public partial class Album : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _AlbumId;
private int _GenreId;
private int _ArtistId;
private string _Title;
private decimal _Price;
private string _AlbumArtUrl;
private EntitySet<Cart> _Carts;
private EntitySet<OrderDetail> _OrderDetails;
private EntityRef<Artist> _Artist;
private EntityRef<Genre> _Genre;
...
你可以发布你的流派类吗? –
类是由Visual Studio 2010使用链接到具有大声明的sql类自动构建的。但是,我包含流派和专辑类。一探究竟。 – arefinsami