I understand that dynamic data will by default display the first string column from the related foreign key table, but I was wondering is it possible to display the other columns related to the foreign key as well? I've seen the example where the ToString
function is overloaded, but I'd like to keep the columns seperate and I'd like to be able to display columns of any datatype such as boolean or integer.
This means I want the fields to be in separate columns ie. a column for CategoryName and a column for CategoryDescription. Overloading the ToString function only creates a single column that combines the two.
jvdub22
Member
2 Points
13 Posts
Displaying other columns from the related foreign key table
Jan 10, 2013 12:20 AM|LINK
I understand that dynamic data will by default display the first string column from the related foreign key table, but I was wondering is it possible to display the other columns related to the foreign key as well? I've seen the example where the ToString function is overloaded, but I'd like to keep the columns seperate and I'd like to be able to display columns of any datatype such as boolean or integer.
march11
Contributor
3017 Points
1367 Posts
Re: Displaying other columns from the related foreign key table
Jan 10, 2013 04:39 PM|LINK
Yes you can do this.
jvdub22
Member
2 Points
13 Posts
Re: Displaying other columns from the related foreign key table
Jan 10, 2013 05:17 PM|LINK
march11,
Can you elaborate or point me to example on how to do this?
march11
Contributor
3017 Points
1367 Posts
Re: Displaying other columns from the related foreign key table
Jan 10, 2013 08:28 PM|LINK
How about posting some of your code so we can see what you are doing and offer suggestions from there.
Linking to a record using a foreign key is really no different that writing the query by using a join.
jvdub22
Member
2 Points
13 Posts
Re: Displaying other columns from the related foreign key table
Jan 10, 2013 08:56 PM|LINK
Here is an example:
I have a table called Products with two fields ProductName and ProductCategoryID.
I have a second table called ProductCategories with the fields CategoryID, CategoryName, CategoryDescription, CategoryRank
Products.ProductCategoryID and ProductCategories.CategoryID are foreign keys.
Out of the box Dynamic Data automatically displays the CategoryName when I view the List page of the Products table.
What I want is to be able to display the CategoryDescription and CategoryRank as well (in their own columns) in the List page of the Products table.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Displaying other columns from the related foreign key table
Jan 12, 2013 02:26 AM|LINK
Hi jvdub22;)
Just override the ToString method and then combine the two properties something like this below:
public override string ToString()
{
"CategoryId:"+CategoryId+"\tCategoryName:"+CategoryName;
}
jvdub22
Member
2 Points
13 Posts
Re: Displaying other columns from the related foreign key table
Jan 14, 2013 06:04 PM|LINK
Hi Decker,
That works for a single column, but I need the properties to be in their own columns.
Any thoughts?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Displaying other columns from the related foreign key table
Jan 15, 2013 12:10 AM|LINK
What does this mean?
jvdub22
Member
2 Points
13 Posts
Re: Displaying other columns from the related foreign key table
Jan 15, 2013 02:13 PM|LINK
This means I want the fields to be in separate columns ie. a column for CategoryName and a column for CategoryDescription. Overloading the ToString function only creates a single column that combines the two.
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Displaying other columns from the related foreign key table
Jan 15, 2013 02:14 PM|LINK
Hi jvdub22, sorry this not possible you can only use the ToString function to combine then into a display string, the main issue here is EF.
I have a simple work around if you are not averse to using Computed Columns in SQL Server?
Always seeking an elegant solution.