entity framework - Can I store enums as strings in EF 5? -


we have been using ef cf while in our solution. big fans! point, we've been using hack support enums (creating field on model; ignore enum durring mapping; , map field column in db have used). traditionally have been storing our enums strings(varchars) in db (makes nice , readable). enum support in ef 5 (beta 2) looks supports mapping enums int columns in db....can ef 5 store our enums string representation.

where "type" enum of type documenttype

public enum documenttype      {         poinvoice,         nonpoinvoice,             } 

i tried map using:

public class workflowmap : entitytypeconfiguration<model.workflow.workflow>     {         public workflowmap()         {             totable("workflow", "workflow");             ...             property(wf => wf.type).hascolumntype("varchar");           }     } 

i thought going magic bullet but..

that throws:

schema specified not valid. errors: (571,12) : error 2019: member mapping specified not valid. type 'dodson.data.dataaccess.efrepositories.documenttype[nullable=false,defaultvalue=]' of member 'type' in type 'dodson.data.dataaccess.efrepositories.workflow' not compatible 'sqlserver.varchar[nullable=false,defaultvalue=,maxlength=8000,unicode=false,fixedlength=false]' of member 'type' in type 'codefirstdatabaseschema.workflow'.

your thoughts?

this not possible. enum in ef has same limitations enums in clr - named set of integer values. check this article confirmation:

the ef enum type definitions live in conceptual layer. clr enums ef enums have underlying type 1 of edm.sbyte, edm.byte, edm.int16, edm.int32 or edm.int64 edm.int32 being default underlying type if none has been specified.

i posted article , related suggestion problem. if want see feature in future please vote suggestion.


Comments