entity framework - EF5 - Navigation properties not loading in a reversed engineered code first model -


i'm banging head on keyboard one, i'm trying rather simple.

i reversed engineered existing database ef power tools, did because database in question quite old , missing lot of foreign keys, or primary key matter. goal able add navigation properties generated model, have cleaner code when querying model.

now have 2 classes user , costcentre, mapped respective tables users , costcentres proper primary keys, pk of users username named userid in costcentres, theoretical relation between 2 1 m (one user can have multiple costcentre). added navigation property user

public virtual icollection<costcentre> costcentres { get; set; } 

i'm initializing list in default constructor simple

    public user()     {         costcentres = new list<costcentre>();     } 

to costcentre added user property

    public virtual user user { get; set; } 

in generated costcentremap class, mapped navigation property

        this.hasrequired(cc => cc.user)             .withmany(u => u.costcentres)             .hasforeignkey(cc => cc.userid); 

now whenever query db.users can't property fill, know navigation property kind of work, because when

db.users .include(u => u.costcentres); 

the resulting query join on proper columns in each table, if

user user = db.users .include("costcentres") .singleordefault(u => u.username == username); 

the property costcentres stays empty.

i'm pretty sure i'm missing quite obvious love of barnaby jones, can't hands on what. appreciated.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -