这是我的实体:
[Table( Name = "PdfMeta" )]
public class Meta
{
[Key()]
public int Id { get; set; }
[Column(Name = "TotalPages")]
public int TotalPages { get; set; }
[Column(Name = "PdfPath")]
public string PdfUri { get; set; }
[Column(Name = "ImagePath")]
public string ImageUri { get; set; }
[Column(Name = "SplittedPdfPath")]
public string SplittedFolderUri { get; set; }
}
这是上下文中的代码:
public DbSet<Meta> PdfMeta { get; set; }
为什么新表 (Metas) 使用 ImageUri、PdfUri ... 列创建?我知道这是按照惯例完成的,但我明确指定了表和列。
最佳答案
ColumnAttribute
的
Name
属性只定义了 getter。改为在构造函数中传递列名:
[Table("PdfMeta")]
public class Meta
{
[Key]
public int Id { get; set; }
[Column("TotalPages")]
public int TotalPages { get; set; }
[Column("PdfPath")]
public string PdfUri { get; set; }
[Column("ImagePath")]
public string ImageUri { get; set; }
[Column("SplittedPdfPath")]
public string SplittedFolderUri { get; set; }
}
BTW ColumnAttribute
在 EntityFramework.dll 中定义。看起来您从 System.Data.Linq.dll 中引用了 ColumnAttribute
关于c# - 实体注释属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15437452/