2013-03-15 16 views
6

Oto moja jednostka:jednostka przyporządkowuje adnotacji nie działają

[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; } 

} 

Oto kod z kontekstu:

 public DbSet<Meta> PdfMeta { get; set; } 

Dlaczego nowa tabela (Metas) został stworzony z ImageUri, PdfUri ... Kolumny ? Wiem, że zostało to zrobione przez konwencję, ale wyraźnie podałem tabelę i kolumny. Właściwość

+0

Czy może używasz dodatkowo płynnej konfiguracji? – JustAnotherUserYouMayKnow

+0

Tak, używam generycznych repozytoriów z IDbContext, ... – NET

+2

Istnieją dwa "ColumnAttribute" upewnij się, że używasz właściwego: 'System.ComponentModel.DataAnnotations.Schema.ColumnAttribute' – nemesv

Odpowiedz

4

Name właściwość ColumnAttribute ma zdefiniowany tylko getter. Przejść nazwa kolumny w konstruktora, a nie:

[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; } 
} 

okazji ColumnAttribute zdefiniowano w EntityFramework.dll. Wygląda na to, że odwołujesz się do ColumnAttribute z System.Data.Linq.dll

+3

@NET ewentualnie używasz niewłaściwego atrybutu . Zweryfikuj, powinien pochodzić z zespołu EF z przestrzeni nazw 'System.ComponentModel.DataAnnotations.Schema' –