Using Visual Studio 2013 in an MVC 5 project with Entity Framework 6, I used "ADO Entity Data Model" (Code First from Database) to add some models to my project. In this case, the tables have relationships.
When the Model wizard was done adding the models & context to my application, I saw these warning attributes on the constructors of the secondary tables. Here is one example.
My question is whether there is some way I can refactor the code so that the warning is no longer there, or is this simply something I learn to ignore because of the way that Entity Framework understands database-first SQL Server relationships?
public partial class StudentList
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2214:DoNotCallOverridableMethodsInConstructors")]
public StudentList()
{
CreditSlipLogs = new HashSet<CreditSlipLog>();
}
// ... code
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CreditSlipLog> CreditSlipLogs { get; set; }
}
}
I looked on MSDN for guidance on CA2214 and CA2227. While no doubt accurate, it wasn't helpful, because I didn't see any instruction on how to resolve this when it was created by the Data Model wizard.