asp.net mvc3 和 Entity Framework 联合使用时发现的问题

wyumening wyumening 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题是在新建Controller类时发现的,新建Controller时选择了新增Data Context Class,将名称命名为
MusicStoreDB,然后生成的代码如下所示:
public class MusicStoreDB : DbContext
{
public DbSet<Album> Album { get; set; }

public DbSet<Genre> Genre { get; set; }

public DbSet<Artist> Artist { get; set; }
}


奇怪的是生成的实体集合的名称像Album,Genre都是单数形式,为什么不是复数形式?我在项目中定义了Album,Genre,Artist三个实体类,放在三个cs文件中,具体代码如下所示:
Album.cs

public class Album
{

public virtual int AlbumId { get; set; }
public virtual int GenreId { get; set; }
public virtual int ArtistId { get; set; }
public virtual string Title { get; set; }
public virtual decimal Price { get; set; }
public virtual string AlbumArtUrl { get; set; }
public virtual Genre Genre { get; set; }
public virtual Artist Artist { get; set; }


}


Genre.cs

public class Genre
{
public virtual int GenreId { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual List<Album> Albums { get; set; }
}


Artist.cs

public class Artist
{
public virtual int ArtistId { get; set; }
public virtual string Name { get; set; }
}


是不是要在哪里配置下?还是说要通过运行EDM向导才能重新配置?
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
wyumening
.NET社区 62,271 成员 668,968 内容