Welcome Guest Search | Active Topics | Log In | Register

Display value other than fk in jqGrid with Entity Framework Options
gutto
#1 Posted : Thursday, July 29, 2010 1:40:48 AM
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
noelt
#2 Posted : Thursday, July 29, 2010 1:51:01 AM
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
gutto
#3 Posted : Thursday, July 29, 2010 4:28:35 AM
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


rumen
#4 Posted : Thursday, July 29, 2010 9:37:44 AM
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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.121 seconds.