Here is my entity:
[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; }
}
Here is code from context:
public DbSet<Meta> PdfMeta { get; set; }
Why new table (Metas) has created with ImageUri, PdfUri ... columns? I know that this was done by convention but I have explisitly specifyed table and columns.
The NotMapped attribute is used to specify that an entity or property is not to be mapped to a table or column in the database. In the following example, the AuditLog class will not be mapped to a table in the database: public class Contact.
Configuration enables you to override EF Core's default behaviour. Configuration can be applied in two ways, using the Fluent API, and through DataAnnotation attributes. Attributes are a kind of tag that you can place on a class or property to specify metadata about that class or property.
Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.
Name
property of ColumnAttribute
has only getter defined. Pass column name in constructor instead:
[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
defined in EntityFramework.dll. Looks like you have referenced ColumnAttribute
from System.Data.Linq.dll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With