locked
Displaying name that is not directly referenced RRS feed

  • Question

  • User1104429570 posted

    Say if I had 3 tables: Keyword, ProductEncoding, and Product.

    Keyword looks like... Keyword_Id (pk), Name, ProductEncoding_Id (fk)

    ProductEncoding has... ProductEncoding_Id (pk), Product_Id (fk), and some other columns

    Product has...  Product_Id (pk), Name, Description

     So right now, DD displays Keyword as Name and ProductEncoding_Id. Which is not very useful, because it's a drop-down of hundred's of Id's. It would be more useful if I was able to display the Product Name. How would I go about doing that?

     Thanks in advance[:)]

    Tuesday, October 28, 2008 12:19 PM

Answers

  • User-330204900 posted

    Hi Jhyoo you would use the DisplayName attribute to set this and create a custom property see here this sample:

    [MetadataType(typeof(MerchantMD))]
    public partial class Merchant 
    {
    	[ScaffoldColumn(true)]
    	public IEnumerable<CATEGORY> Categories
    	{
    		get
    		{
    			var DC = new ManyDataContext();
    			IEnumerable<Category><CATEGORY> categories = from mc in DC.MerchantCategories
    					      where mc.MerchantId == this.Id
    					      select mc.Category;
    			return categories;
    		}
    	}
    
    	public class MerchantMD
    	{
    		public object Id { get; set; }
    		public object Name { get; set; }
    		public object MerchantCategories { get; set; }
    	}
    }

    Also see David Ebbo's sample template  for Many to Many here

    Hope this helps [:D]

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 28, 2008 12:52 PM

All replies

  • User-330204900 posted

    Hi Jhyoo you would use the DisplayName attribute to set this and create a custom property see here this sample:

    [MetadataType(typeof(MerchantMD))]
    public partial class Merchant 
    {
    	[ScaffoldColumn(true)]
    	public IEnumerable<CATEGORY> Categories
    	{
    		get
    		{
    			var DC = new ManyDataContext();
    			IEnumerable<Category><CATEGORY> categories = from mc in DC.MerchantCategories
    					      where mc.MerchantId == this.Id
    					      select mc.Category;
    			return categories;
    		}
    	}
    
    	public class MerchantMD
    	{
    		public object Id { get; set; }
    		public object Name { get; set; }
    		public object MerchantCategories { get; set; }
    	}
    }

    Also see David Ebbo's sample template  for Many to Many here

    Hope this helps [:D]

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 28, 2008 12:52 PM
  • User-1005219520 posted

    jhyoo,

    You have correctly recognized the algorithm DD uses to select the foreign key column to display- the first string column in the FK table. To change the column displayed just use the DisplayColumn Attribute.

    Tuesday, October 28, 2008 1:27 PM
  • User-330204900 posted

    Hi Rick, if you look at Jhyoo's model he has a many to many relationship which my first suggestion is for L2S and the second for EF

    [:D]

    Tuesday, October 28, 2008 1:44 PM
  • User1104429570 posted

    I believe this is what I'm looking for. But when I try to say return "categories", from your example, the column name is getting displayed but returning no values. I tried to step into it, but it skips over that bit. The first thing you metioned was to use the DisplayName attribute, but doesn't that just change the display name on the column? Any ideas? Btw, I am using L2S.

    Thanks

    Tuesday, October 28, 2008 4:23 PM
  • User1104429570 posted

     <strike>Nevermind, it works. My query was wrong[:D]</strike>

    After correcting my query and verifying that it's returning the results I need, nothing shows up. It does create the column for the referenced table, but there is no data. Any ideas?

    Thanks

    Tuesday, October 28, 2008 4:49 PM