none
Lookup Tables and Enums RRS feed

  • Question

  •  I have a table with lots of columns of type smallInt which are actually lookup values from referential tables.

     One approach is use to Enumeration type in the Entity Framework and easily change values of the those fields.

     However that is not ideal, since those are essentially hardcoded.

     I require flexibility because the values in those lookup tables and their order might get changed in database over time.

     Any solution to this ?


    Shahid Roofi

    Thursday, December 8, 2016 9:35 PM

All replies

  • Hi Shahid,

    >>Any solution to this ?

    The following article provide a solution, which use Configuration.Seed() method that is called every time the migrations are applied. It is called even if there are no pending migrations.

    https://coding.abel.nu/2013/11/enums-and-lookup-tables-with-ef-code-first/

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. 

    Microsoft does not control these sites and has not tested any software or information found on these sites;Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information
    found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 9, 2016 3:02 AM
    Moderator