Say I have the following entity:
public class Post
{
public int Id { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
When I retrieve a Post object from the database, I need to convert the Comments
collection into an EntityCollection<T>
so that I can check some EF4 related data about the collection, such as if the data was eager loaded or not.
Unfortunately, if I try to do a direct cast from ICollection<T>
to EntityCollection<T>
, I get an exception due to the fact that the Comments
property is a System.Collections.Generic.List<T>
and cannot be converted into an EntityCollection<T>
.
So how do I go about getting EF information on a collection when using code-first?