[英]Compilation error in a view(.cshtml) file
我想您知道mvcmusicstore.codeplex.com上的在线MvcMusicStore应用程序教程。 我正在使用MS SQl Server 2008专业版而不是使用MVC3的精简版来开发此项目。 我使用链接到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<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;
...
是的,我找到了解决方案。 缺少程序集引用。 我只是在web.config文件中添加了程序集引用。 即
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.