|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/29/2010 Posts: 2
|
Hi
Wondered if there is a way to display instead of foreign key value some other column value from foreign table with jqGrid MVC .NET.
So lets say I got two tables 1st: Emplyee table 2nd Role table. Employee can be in only one role at a time and is related with Role table by fk as
Employee.RoleID --> Role.ID.
Is there a way to display in the jqGrid Role.Name instead of Role.ID? Note that I am using Entity Framework.
I'd be greateful for any clues
gut
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 7/12/2010 Posts: 82
|
Hello, The easiest way to achieve this is to join both tables with LINQ. Since the result will be IQueryable (what the grid expects) you can join any column from a related table to the primary datasource. There is a superb forum thread on Stackoverflow demonstrating how to join tables with LINQ. The result of the join can be bound the the grid. Just make sure you define the respective columns first in the Model. Kind Regards, NoelT Trirand Inc. Support Team
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/29/2010 Posts: 2
|
Thats really good and easy solution. Thank u very much noelt. I done something like:
FROM e in db.Employee JOIN r in db.Role on e.RoleID equals r.ID SELECT new { e.ID, e.Name, ... ,r.RoleName };
and then in my grid model i modeled columns accordingly: "ID", "Name", ... , "RoleName"
All's working fine now. Thanks again! :D
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 10/15/2009 Posts: 379
|
Great, thanks for sharing the solution in our public forums. Kind Regards, Rumen Stankov (MCPD) Trirand Inc.
|
|
|
|
Guest
|
YAFPro Theme Created by Jaben Cargman (Tiny Gecko)Powered by YAF 1.9.3 |
YAF © 2003-2009, Yet Another Forum.NETThis page was generated in 0.121 seconds.