none
Entity Framework: Map dictionary to a table RRS feed

  • Question

  • I have to deal with database, where new tables are added constantly to represent some
    users
    data, the solution I came with is to represent each table with dictionary where keys are columns' names, so is it doable in entity framework to map such a dictionary to a table where each value must be inserted in a column having its key as name ? Thanks for all the help!


    Wednesday, April 26, 2017 9:52 AM

All replies

  • Wm92

    I am not sure I understand you fully , but I will attempt to answer , entity framework has 3 database manipulation strategies code-first approach , model first approach and not mistaking database first , I have  used  the first  two except Database approach , to map a field (column) as a key code first implement require you to place an implementation of System.Serialization.DataAnotations , his will expose you to the entity mapping properties like enabling column index's and Keys property's if you are using model first approach you can setup those properties directly on the edmx file UI . there are many ways  to implement you repository you can map entities in dictionaries it doesn't matter as long as you understand .Net . the main confusing part of your question is on statement 'keys are columns' names' ? are you  referring to table keys , or the dictionary key ?

    also a dictionary can contain both table (entity) key and the actual table (entity) as ()=>

    Dictionary<int,Person> personDC=new Dictionary<int,Person>() such that key is the primary key of table(entity) Person.

    Wednesday, April 26, 2017 11:48 PM
  • >so is it doable in entity framework to map such a dictionary to a table

    No.  EF requires each table to be mapped to a class and each column to be mapped to a property.

    You can do this using ADO.NET directly.

    David


    Microsoft Technology Center - Dallas
    My blog

    Thursday, April 27, 2017 1:12 AM