Reputation: 480
When trying to create a initial migration of my EF7 Code First database by executing from the command line:
dnx ef migrations add Initial
I get the error:
System.InvalidOperationException: The property 'ExerciseTemplateId' cannot exist on entity type 'object' because the property is not marked as shadow state and no corresponding CLR property exists on the underlying type. Full Stacktrace
Any ideas?
For some reason EF7 doesn't seem to like the primary key property ExerciseTemplateId on my Model:
public class ExerciseTemplate
{
public int ExerciseTemplateId { get; set; }
public string InitalCode { get; set; }
public string ClassName { get; set; }
public string MainMethodName { get; set; }
public int ExerciseForeignKey { get; set; }
public Exercise Exercise { get; set; }
}
The only interesting part of the ExerciseTemplate model is a one to one relationship with the Exercise model:
public class Exercise
{
public int ExerciseId { get; set; }
public string Name { get; set; }
public string Guidance { get; set; }
public ExerciseTemplate Template { get; set; }
public List<ExerciseCategory> Categories { get; set; }
public List<Test> Tests { get; set; }
}
This question is already long so my DBContext is in this DBContext Gist
All the Models and the DB Context can be found at this Models and Context Gist
Upvotes: 0
Views: 1749
Reputation: 13458
Long story short: do not use object
or Type
as property type in your model classes. It has no representation in the database.
If you absolutely need to store arbitrary objects, you may use some serializer and store the serialized objects as BLOB in the database.
Upvotes: 1