I have looked at several possible solutions to my issue but did not find the right one.
I need a full set, that is, I need to fetch the types that are also of a base type. i.e. the ActionHistory type, as well as all others, which inherit from the ActionHistory base class. My problem was that I was getting all entities but those of the ActionUpdate type did not have the ActionUpdateDetails collection filled.
My problem is that I am unable to retrieve the ActionUpdateDetails data within the derived ActionUpdate class.
There are three classes in the model:
public class ActionHistory
{
public int Id {get;set;}
}
public class ActionUpdate : ActionHistory
{
public ICollection<ActionUpdateDetail> ActionUpdateDetails{get;set;}
}
public class ActionUpdateDetail
{
int Id{get;set;}
public string Field{get;set;}
public string Value{get;set;}
}
I tried implementing the solution from this suggestion: Entity Framework: Inheritance and Include
Like this:
var result = from actionHistory in ActionHistories
select new {
actionHistory,
actionUpdateDetails = actionHistory is ActionUpdate ?
(actionHistory as ActionUpdate).ActionUpdateDetails : null
};
All I get is the exception message:
Unable to create a constant value of type 'System.Collections.Generic.ICollection`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
Then I tried to simulate the situation outside the EF and it worked. I am using a POCO model and have extracted the involved classes into a separate project, filled the structure sample with data, and tested it with a success, i.e. ActionUpdateDetails collection was filled with the data.
Any help on this will be appreciated!
N.