locked
Displaying other columns from the related foreign key table RRS feed

  • Question

  • User-636272623 posted

    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.

    Wednesday, January 9, 2013 8:20 PM

Answers

  • User-330204900 posted

    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.

    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

    I have a simple work around if you are not averse to using Computed Columns in SQL Server?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2013 10:14 AM

All replies

  • User-359936451 posted

    Yes you can do this.

     

    Thursday, January 10, 2013 12:39 PM
  • User-636272623 posted

    march11,

    Can you elaborate or point me to example on how to do this?

    Thursday, January 10, 2013 1:17 PM
  • User-359936451 posted

    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.

     

    Thursday, January 10, 2013 4:28 PM
  • User-636272623 posted

    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.

    Thursday, January 10, 2013 4:56 PM
  • User3866881 posted

    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;
    }

    Friday, January 11, 2013 10:26 PM
  • User-636272623 posted

    Hi Decker,

    That works for a single column, but I need the properties to be in their own columns.

    Any thoughts?

    Monday, January 14, 2013 2:04 PM
  • User3866881 posted

    the properties to be in their own columns.

    What does this mean?

    Monday, January 14, 2013 8:10 PM
  • User-636272623 posted

    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.

    Tuesday, January 15, 2013 10:13 AM
  • User-330204900 posted

    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.

    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

    I have a simple work around if you are not averse to using Computed Columns in SQL Server?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2013 10:14 AM
  • User-636272623 posted

    sjnaughton,

    can you show me an example of the computed columns?

    thanks

    Wednesday, January 16, 2013 12:05 AM
  • User-330204900 posted

    Hi jvdub22, below is an example of a computed column see this line [DORetirement] AS (dateadd(year,(60),[DOBirth])-(1)) PERSISTED remember this is all accomplished in the data base, I often use scalar vaued functions and pass in some (i.e. value PK or FK column) and then access related tables for the values.

    USE [AdventureWorks]
    GO 
    -- Create Table with computed column
    CREATE TABLE [dbo].[CCtest]
    (
    [empNumb] [int] NULL,
    [DOBirth] [datetime] NULL,
    [DORetirement] AS (dateadd(year,(60),[DOBirth])-(1)) PERSISTED
    )
    GO

    Wednesday, January 16, 2013 3:49 AM