c# - LINQ Include command mvc3 and webgrid -
i'm doing asp.net mvc3 application similar amazon gift card system. have model named cards related models users, cardstatus, paymentmethod , cardhistory. i'm doing grid displays data of cards (creator, initial amount, status). i'm using webgrid display data. card can have multiple status in time, when added controller, asp generated code:
public viewresult index() { var cards= db.cards.include(t => t.cardstatus).include(t => t.paymentmethod).include(t => t.users); return view(cards.tolist()); }
the problem need show in webgrid latest card status generated query brings status, gives me error in webgrid "column cardstatus.status.name doesn't exists" here webgrid code:
@grid.gethtml( headerstyle: "header", tablestyle: "table table-striped table-bordered table-hover", columns: new[] { grid.column("cardid", header: "card"), grid.column("user.id", header: "creator"), grid.column("initialamount", header: "amount"), grid.column("cardstatus.status.name", header: "status") }
) i've tried linq statements i'm new @ did not work. how can bring card info latest status? thanks
cardstatus
is collection of status card-object, right? add property in card-class:
public partial class card { public cardstatus laststatus { { return cardstatus.last(); } } }
that usefull if needed access last status multiple times. add column in webgrid that:
grid.column("laststatus.name", header: "status")
you solve problem linq-query. on here: msdn: 101 linq samples (especially join-operator useful: linq - join operators)
thomas
Comments
Post a Comment