Using Entity Framework 6, I'm wondering if I need a Mapping file. I have a model defined like this:
[Table("UploadedFile")]
public partial class UploadedFile
{
[Key, ForeignKey("Resource"), DatabaseGenerated(DatabaseGeneratedOption.None)]
public System.Guid FileId { get; set; }
public virtual Resource Resource { get; set; }
//...
public System.DateTime Modified { get; set; }
public bool IsActive { get; set; }
public byte[] RecordVersion { get; set; }
public UploadedFile()
{
Resource = new Resource();
}
}
And my mapping file like this:
public class UploadedFileMapping : EntityTypeConfiguration<UploadedFile>
{
public UploadedFileMapping()
{
//Primary key
HasKey(t => t.FileId);
//Constraints
Property(t => t.RecordVersion).IsRowVersion();
}
}
Can I just rely on attributes in the model? What are the pros/cons of using a mapping file?
I believe the [Key]
attribute in the model negates the need for HasKey, is this correct?