entity framework - Unflatten a database record into Master/Detail in EF 5 Code First -


i have legacy database table has following structure

create table [dbo].[master_project](     [data_id] [bigint] identity(1,1) not null,     ......     [genre_data_id] [bigint] null,       [additional_genre_data_id] [bigint] null,     [additional_genre_2_data_id] [bigint] null ) 

i want have following classes mapped out using ef 5 (code first)

public class project {    public long id {get;set;}    public icollection<genre> genres {get;set;} }  public class genre {    public long id {get;set;}    // other stuff } 

at first tried making genres array , mapping this

    hasoptional(t => t.genres[0]).withoptionaldependent().map(m => m.mapkey("genre_data_id"));     hasoptional(t => t.genres[1]).withoptionaldependent().map(m => m.mapkey("additional_genre_data_id"));     hasoptional(t => t.genres[2]).withoptionaldependent().map(m => m.mapkey("additional_genre_2_data_id")); 

but generates error, t.genres[0] not valid property. (which makes sense)

any idea on how go doing this? thanks!

what want has nothing ef - need implement partial class of entity new method or property returns collection of items. will, of course, need populate collection values in various genre data id properties. example:

public icollection<genre?> genredataids {          {         var col = new list<genre?>() { genre_data_id_navproperty, additional_genre_data_id_navproperty, ..., addition_genre_n_data_id_navproperty };          return col;     } } 

your navigation properties named genre1, genre2; i've added _navproperty column name illustrative purposes.

if want use collection update underlying db record, more complex (easiest implementation implement setgenredataid( int index, int? value ) method )


Comments