Home > Net > EF multi-table query results into the ViewModel
EF multi-table query results into the ViewModel
Time:05-27
I in the project through the ef two table query to obtain a var data collection
Public dynamic GetAllPalte () { Using (CSDC_DBEntities context=new CSDC_DBEntities ()) { Var paltes=the from p in the context. T_palte The join u in the context. T_user on p.u _id equals u.u _id Select new { P_id=p.p _id, P_name=p.p _name, P_logo=p.p _logo, P_introduce=p.p _introduce, P_discussnums=p.p _discussnums, U_id=u.u _id, U_name=u.u _username
}; Return paltes. ToList ();
} }
I think it is in the controller is converted to the ViewModel is bound to the View of What should I do?
CodePudding user response:
I have done such a try The ViewModel code
Public class BBSModel { Public int p_id {get; set; } Public string p_name {get; set; } Public string p_logo {get; set; } Public string p_introduce {get; set; } Public int u_id {get; set; } Public string u_username {get; set; } }
The View in the View Model is considered to be the current View of entity object, the object does not support iteration,
CodePudding user response:
@ model in the view at the top of the statement, if return from controller is entity, is declared as @ model XXX. XXX. BBSModel, if it is other types, the statement for the corresponding type can, for example: @ model List , this Model is List , can be normal iteration,