Enum in Data Model is causing invalid schema error at runtime.

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
BryanJ
Posts: 3
Joined: Tue 25 Jun 2013 04:25

Enum in Data Model is causing invalid schema error at runtime.

Post by BryanJ » Tue 25 Jun 2013 05:36

Hello,

In the Entity Developer I have added external enumerations (base type is "int") from another assembly. And in some classes/tables I have changed a property to be of the enum type that I have added to the data model. The model shows no errors and builds in my Visual Studio 2012 project.

In my source code I create a context and call context.CreateDatabase(). After this if I try to add any objects, something.AddObject(...), to the context an exception is thrown with the following message:
The property 'Orientation' on type 'TrafficDataModel.DataCollection' is attributed with EdmScalarPropertyAttribute but returns the type 'TrafficBase.CardinalDirection', which is not a primitive type or a recognized enumeration type.
Where "TrafficBase.CardinalDirection" is the external enumeration type that I added previously.

If I remove the "EdmScalarPropertyAttribute" attribute from the generated Designer code for the enumeration type properties it seems to work. However, I later run into another error when trying access any object collections on my context that have the enumeration type property in their elements.
Message=The number of members in the conceptual type 'TrafficDataModel.DataCollection' does not match with the number of members on the object side type 'TrafficDataModel.DataCollection'. Make sure the number of members are the same.
Is there something I am missing for adding existing enumerations to my Data Model? Also I am using dotConnect for SQLite if it matters, Entity Framework 5, .NET 4.5.
Thank you for your time!

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Re: Enum in Data Model is causing invalid schema error at runtime.

Post by Shalex » Thu 27 Jun 2013 14:20

BryanJ wrote:In my source code I create a context and call context.CreateDatabase(). After this if I try to add any objects, something.AddObject(...), to the context an exception is thrown with the following message:
The property 'Orientation' on type 'TrafficDataModel.DataCollection' is attributed with EdmScalarPropertyAttribute but returns the type 'TrafficBase.CardinalDirection', which is not a primitive type or a recognized enumeration type.
Thank you for the report. We have reproduced the problem and are investigating it. We will post here about the result.

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Re: Enum in Data Model is causing invalid schema error at runtime.

Post by Shalex » Wed 03 Jul 2013 11:14

You have encountered a limitation of Entity Framework: http://connect.microsoft.com/visualstud ... dding-enum.

Your approach will work if you change a code generation template: use DbContext instead of ObjectContext.

If you want to stay with ObjectContext, you should implement the following changes:
1) move the definition of your enum to the assembly with your descendant of ObjectContext
2) put the EdmEnumType attribute (and set the values of Name and NamespaceName)
3) specify the DataContract and EnumMember attributes if you need serialization/deserialization
Example:

Code: Select all

namespace Model {
  [System.Data.Objects.DataClasses.EdmEnumTypeAttribute(Name = "Enum1", NamespaceName = "Model")]
  [System.Runtime.Serialization.DataContract()]
  public enum Enum1 {
    [System.Runtime.Serialization.EnumMember()]
    a,
    [System.Runtime.Serialization.EnumMember()]
    b
  };
}

Post Reply