我想你知道 mvcmusicstore.codeplex.com 上的在线 MvcMusicStore 应用程序教程。我正在使用 MVC3 在 MS SQl Server 2008 专业版而不是精简版下开发这个项目。我使用Link to Sql类作为模型类。它像往常一样工作。但是,视图文件 Browse.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;
...
专辑类,
[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;
...