【发布时间】:2012-08-04 18:35:24
【问题描述】:
我在个人 ASP.NET MVC 3 项目中使用 EF Code First (4.3.1),具有非常简单的域模型,并且我几乎处于 EF 将以我的方式生成 DB 架构的地步想要。
领域模型有两个类:Painting 和Gallery。每个Painting 都属于一个Gallery,Gallery 有两个指向Painting 的虚拟属性:一个指示哪幅画是它的封面图像,一个指示哪幅画是滑块图像显示在主页上。
课程如下。我删除了一些注释和不相关的属性以使其可读。
public class Gallery
{
public Gallery()
{
Paintings = new List<Painting>();
}
[ScaffoldColumn(false)]
[Key]
public int GalleryId { get; set; }
public string Name { get; set; }
[ScaffoldColumn(false)]
[Column("LaCover")]
public Painting Cover { get; set; }
[ScaffoldColumn(false)]
[Column("ElSlider")]
public Painting Slider { get; set; }
[ScaffoldColumn(false)]
public virtual List<Painting> Paintings { get; set; }
}
和绘画:
public class Painting
{
[ScaffoldColumn(false)]
[Key]
public int PaintingId { get; set; }
public string Name { get; set; }
public int GalleryId { get; set; }
[Column("GalleryId")]
[ForeignKey("GalleryId")]
[InverseProperty("Paintings")]
public virtual Gallery Gallery { get; set; }
public string Filename { get; set; }
}
它为类及其关系生成正确的数据库模式,我唯一的小问题是我还没有找到一种方法来控制它为Cover 和Slider 的虚拟属性提供的列名在Gallery 表中。
它会将它们命名为 Cover_PaintingId 和 Slider_PaintingId。
我尝试使用[Column("columnNameHere")] 属性,但这根本不影响它。如“我输入了某个不相关的单词,但它没有出现在架构中”。
我想将其命名为CoverPaintingId,不带下划线。
非常感谢任何帮助。谢谢
【问题讨论】:
标签: c# .net entity-framework-4