Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF5 Enum mapping to external type issue

Is it just me or does this not seem to work?

In model first I dragged in a simple table and created an enum (via convert to enum). Now I've tried with and without creating the enum items in the dialog, but if I tick the reference external type I get:

Schema specified is not valid. Errors: No corresponding object layer type could be found for the conceptual type 'ControlPanelDevModel.EventType'.

like image 969
Ceric Brasey Avatar asked Sep 17 '12 09:09

Ceric Brasey


2 Answers

Ok as a supplement to the above I found I've been getting the same error when the mapping an external Enum to database type of tinyint.

The solution is to have your Enum inherit from type "byte" as specified in this post.

Tinyint(byte),SmallInt(Int16) not compatible with Enum in EF5

like image 138
ledragon Avatar answered Nov 09 '22 20:11

ledragon


Take a look at my blogpost - it shows how to create and use external enum types: http://blog.3d-logic.com/2012/09/11/using-exisiting-enum-types-in-entity-framework-5/ If you are using EF5 RTM (and not EF June CTP 2011) shipped with .NET Framework 4.5 you don't need to specify members of the EDM Enum Type. The important thing is to make sure that the EDM Enum Type name match the name of the external CLR enum type and that the underlying types are the same (if no underlying type is specified Edm.Int32 will be used - similarly to C#/VB.NET - where int is used). If you decide to sepcify members on the EDM Enum Type you must not have a member whose name and/or value is different from the C#/VB enum type members. You also don't have to specify all the members of the CLR enum type in the EDM enum type (in fact, as I pointed above, you may not have any members as you did and everything is supposed to work).

like image 10
Pawel Avatar answered Nov 09 '22 18:11

Pawel