Reputation: 21216
I have a file Unit.cs
public class Unit
{
public UnitType UnitTypeState {get;set;}
}
public enum UnitType
{
Folder = 0,
Teststeps = 1,
}
When I put the enum definition into another class like UnitDTO I got this exception:
The property 'UnitTypeState' is not a declared property on type 'Unit'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.
Well thats not truee hehe the property UnitTypeState is a declared property in the Unit class class.
How can I fix that without moving the enum back to the Unit class?
UPDATE
I have still done some research about the bug:
"The context cannot be used while the model is being created."
The odd thing is I get this exception on a entity which is the parent of the entity with the UnitTyeState property ?!
using (var context = new ITMS.DataAccess.ITMSContext())
{
return context.Templates.ToList();
}
so it seems the template entity is created then this exception is thrown? Or behaves EF like this: At the first DB access at all every entities or the whole model is created?
Upvotes: 1
Views: 2658
Reputation: 31610
Nested types are currently not supported by EF - applies to both StructuralType (i.e. entity and complex types) and enum types.
Adding a link to the EF work item that is exactly about this issue: http://entityframework.codeplex.com/workitem/119
Upvotes: 0
Reputation: 733
Try using the following, Perhaps the enum just needs to derive from a primitive to work?
public enum UnitType : int
{
Folder = 0,
Teststeps = 1
}
Upvotes: 0