Click here to Skip to main content
14,699,608 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an MVC model,
Imports System.ComponentModel.DataAnnotations

Public Class Person
    <key>
    Public Property Id as integer
    Public Property Sex as Gender
End Class

</key>

Unfortunately this does not store the Sex property into the db when the framework creates it. It contains only the id key field.
As a workaround, I thought this would be a good solution

Imports System.ComponentModel.DataAnnotations
Public Class Person
    <key>
    Public Property Id as integer

    <notmapped>
    Private Property sSex as Gender

    Public Property Sex as integer
    Get
        Return sSex
    End Get
    Set(value as integer)
        sSex = value
    End Set

End Class
</notmapped></key>

Unfortunately this ruins the whole structure of the class itself, as I'd like to use the Sex as a gender rather than as an integer. Is there anyway to force MVC3 to store the Enum value as integer automatically?
Posted
Updated 24-Jun-11 10:53am
v2
Comments
Karthik. A 24-Jun-11 15:53pm
   
PS - Edited the tags

1 solution

Database data types are not supporting enum types.

Thus when it is saving your enum type it does not have any counter part at database level to map with so it is better to make integer property for enum.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900