Saturday 15 March 2014

entity framework - MVC class within class not being populated -



entity framework - MVC class within class not being populated -

trying create mvc application of existing php/mysql library application. i'm having problem getting basic things work, , sense idiot.

i have next classes defined:

book class:

public class book { public int bookid { get; set; } public string bookname { get; set; } public int? seriesid { get; set; } public int genreid { get; set; } public genre genre { get; set; } etc }

genre class:

public class genre { public int genreid { get; set; } public string genrename { get; set; } public virtual icollection<book> books { get; set; } }

when run see each book object created has genre object, null, , info genres isn't beingness populated.

the genreid in book class foreign key

can please tell me doing wrong?

the genre property on book should virtual. if isn't virtual plain query retrieves books leave genre blank. making virtual allows entity framework create dynamic proxy class, inherited book, implements getter of genre property code issue query populate , homecoming genre database.

you've made genre's collection of books virtual work lazy fetching property already.

an alternative lazy loading utilize .include on query include genre property.

entity-framework model-view-controller

No comments:

Post a Comment