c# - EF: mapping class properties to Rows not Columns -


do have idea how map properties of class rows in table? let's have table [id, key, value].

i have predefined key values (on attributes example) mapped properties in class, values taken value column.

example:

table

 --------------------------------- | id  | key        | value        |  --------------------------------- | 1   | name       | jon          |  --------------------------------- | 2   | surname    | doe          |  --------------------------------- 

class

public class bar {     public string name { get; set; }     public string suname { get; set; } } 

is there in ef achieve or have write own custom code?

br

you can't map values column properties. have key-value table, suggest read table content dictionary.

first, should have entity properties correspond table column names:

public class foo {    public string key { get; set; }    public string value { get; set; } } 

after map entity table, can read table content dictionary:

var values = context.foos.todictionary(f => f.key, f => f.value); 

now can values keys:

var name = values["name"]; 

you can use dictionary backing store properties:

public void bar {     private dictionary<string, string> values =           context.foos.todictionary(f => f.key, f => f.value);      public string name { { return values["name"]; } }     public string surname { { return values["surname"]; } } } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -