locked
ScaffoldColumn(false) Doesn't (Always) Hide Identity Keys RRS feed

  • Question

  • User1288251396 posted

    I have an Entities Dynamic Data site, and I'm trying to use ScaffoldColumn(false) to hide Identity=Yes Primary Keys.

    Here's one that doesn't work:

    using System.ComponentModel.DataAnnotations;
    
    namespace FindMyDentistAdmin
        {
        [MetadataType(typeof(LookupDentistStatusMetadata))]
        public partial class LookupDentistStatus
            {
            }
        public class LookupDentistStatusMetadata
            {
            [ScaffoldColumn(false)]
            public object DentistStatusId;
            }
        }

    And here's my table definition:

    USE [MyDatabase]
    GO
    
    /****** Object:  Table [dbo].[LookupDentistStatus]    Script Date: 11/08/2011 09:25:56 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    SET ANSI_PADDING ON
    GO
    
    CREATE TABLE [dbo].[LookupDentistStatus](
    	[DentistStatusId] [int] IDENTITY(1,1) NOT NULL,
    	[StatusName] [varchar](31) NOT NULL,
    	[IsActive] [bit] NOT NULL,
     CONSTRAINT [PK_LookupDentistStatus] PRIMARY KEY CLUSTERED 
    (
    	[DentistStatusId] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    
    SET ANSI_PADDING OFF
    GO
    
    

    Does anybody see the problem?

    Tuesday, November 8, 2011 12:24 PM

Answers

  • User-330204900 posted

    OK moving on :) try this metadata

    using System;  
    using System.Collections.Generic;  
    using System.ComponentModel;  
    using System.ComponentModel.DataAnnotations;  
    using System.Linq;  
    using System.Web;  
      
    namespace FindMyDentistAdmin  
    {  
        [MetadataType(typeof(DentistMetadata))]  
        public partial class Dentist  
        {  
            internal class DentistMetadata  
            {  
                [ScaffoldColumn(false)]  
                [DisplayName("Date Created")]  
                public object Created { get; set; }

    // this is fake column to generate an error if the metadata is not being seen
    public object BOGUS { get; set; } 

    } } }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 12, 2011 12:08 PM

All replies

  • User-330204900 posted

    Hi Ed, this is usually because the metadata is not being read, what I do to test this is add abogus property if the metadata is being seen then a runtime error will be thrown if it is not seen the it will run fine. could you please try that, alternativly use the DisplayName attribute to change a columns disply name and see if that changes for that entity.

    Wednesday, November 9, 2011 9:56 AM
  • User1288251396 posted

    add abogus property
    Where?  (I'm a real newbie!)

    DisplayName attribute to change a columns disply name
    When I try to use the DisplayName, I get an "Identifier Expected" error for the DisplayName statement.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;
    
    namespace FindMyDentistAdmin
        {
        [MetadataType(typeof(DentistMetadata))]
        public partial class Dentist
            {
            }
    
        public class DentistMetadata
            {
            [ScaffoldColumn(false)]
            [DisplayName("Date Created")]
            public object Created;
            }
        }

    Did I mention that I'm a real newbie?  ;-)

    Wednesday, November 9, 2011 10:58 AM
  • User-330204900 posted

    try this metadata

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.ComponentModel.DataAnnotations; 
    using System.Linq; 
    using System.Web; 
     
    namespace FindMyDentistAdmin 
    { 
        [MetadataType(typeof(DentistMetadata))] 
        public partial class Dentist 
        { 
            internal class DentistMetadata 
            { 
                [ScaffoldColumn(false)] 
                [DisplayName("Date Created")] 
                public object Created { get; set; }; 
            } 
        } 
    }

    Also note that when you greate an entity model if you create in in a folder the namespace will have that folder as a part of the name.

    e.g. if you model was in you Models folder then your namespace would be

    namespace FindMyDentistAdmin.Models

    Wednesday, November 9, 2011 11:07 AM
  • User1288251396 posted

    Stephen,

    Thanks for taking the time with me.

    I tried your metadata, and the error went away.  Is there a tutorial somewhere that explains how to work with these attributes?

    And after putting in your suggested metadata, the Created column still displays, and NOT with the "Date Created" DisplayName I specified.

    The namespace is right - I have my partial Dentist class in the root folder.  (Yeah, I know, but it sidesteps any namespace issues.  Once I get a better handle on how all of this works, I plan to clean it up.)

    Thanks again.

     

    Wednesday, November 9, 2011 11:18 AM
  • User1043796333 posted

    Are you by any chance using different links to call your pages. Could it be tha in any of this links you're calling standard rather than customized pages?

    Friday, November 11, 2011 3:18 PM
  • User1288251396 posted

    Are you by any chance using different links to call your pages. Could it be tha in any of this links you're calling standard rather than customized pages?

    No, other than adding the ScaffoldColumn and DisplayName attributes, I haven't done any customization at all.  It's all just standard Dynamic Data scaffolding.

    Friday, November 11, 2011 5:43 PM
  • User-330204900 posted

    Hi Ed, as I have said before this is always due to the metadata not being read.

    Saturday, November 12, 2011 8:45 AM
  • User1288251396 posted

    Yes, Stephen, and I believed you both times.  ;-)

    I just don't know what to do about that.  (I haven't had the time to check out all the links you posted, so maybe ...)

    Saturday, November 12, 2011 9:26 AM
  • User-330204900 posted

    OK moving on :) try this metadata

    using System;  
    using System.Collections.Generic;  
    using System.ComponentModel;  
    using System.ComponentModel.DataAnnotations;  
    using System.Linq;  
    using System.Web;  
      
    namespace FindMyDentistAdmin  
    {  
        [MetadataType(typeof(DentistMetadata))]  
        public partial class Dentist  
        {  
            internal class DentistMetadata  
            {  
                [ScaffoldColumn(false)]  
                [DisplayName("Date Created")]  
                public object Created { get; set; }

    // this is fake column to generate an error if the metadata is not being seen
    public object BOGUS { get; set; } 

    } } }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 12, 2011 12:08 PM