I am working on an ASP.NET MVC web application. And I have mapped my database tables using ADO.NET Entity Framework, which generated a .edmx file. Now one of the limitations of the generated .edmx file, is that all the collections which represent a parent-child relation, will be defined as ICollection. For example I have this Question model class:-
public Question()
{
this.Anwers = new HashSet<Anwer>();
}
public int Id { get; set; }
public string QuestionDesc { get; set; }
public int Order { get; set; }
public bool Active { get; set; }
public virtual ICollection<Anwer> Answers { get; set; }
Here is the answer model:-
public partial class Anwer
{
public Anwer()
{
this.UserFormsAnswers = new HashSet<UserFormsAnswer>();
}
public int Id { get; set; }
public string AnwerDesc { get; set; }
public int QuestionID { get; set; }
public bool Correct { get; set; }
public virtual Question Question { get; set; }
public virtual ICollection<UserFormsAnswer> UserFormsAnswers { get; set; }
}
Now the problem with the ICollection compared to IList<> is that I can not use indexer to get the values of the Answers related to a question. While if I have IList<> instead of ICollection<> I can indexing the Answers for a Question.
So my question is what is the best appraoch to override my public virtual ICollection<Anwer> Answers { get; set; } to be public virtual IList<Anwer> Answers { get; set; }? Of course modifying the automatically generated .edmx file should be avoided as my modifications will be overridden if I remap my database tables..