locked
Dynamic Data Scaffolding Issue RRS feed

  • Question

  • User-1084196641 posted

    Hi

    I have created a Dynamic Data Application that works beautifully. But the big issue is that I can't see to get my partial classes with its underlying structured to be seen at all.

    I have an entity model called WebServiceMetadataDB.edmx that I put in my App_Data folder.

    My Global.asax is set to True. I wrote some code that removed tables from my Global_asax.DefaultModel.VisibleTables based on what button the user pushes so that the next page opens with the table list based on what is needed. i.e. button for my client and authkeys will open page that only return the table list that includes the client table and authkeys table.

    I wrote a class called Clients and put it in my App_Code folder.

    This never gets called or overwrites the entity Client initial load.

    Imports Microsoft.VisualBasic
    Imports System.ComponentModel.DataAnnotations
    
    
    <MetadataType (GetType(ClientsMetaData))> _
    Partial Public Class Clients
    
    End Class
    
    Partial Public Class ClientsMetaData
        <ScaffoldColumn(False)> _
        Public Property ClientGUID As Object
    
        <Display(Name:="Client Name")> _
        Public Property ClientName As Object
    
        <Display(Name:="Contact Name")> _
        Public Property ContactName As Object
    
        <Display(Name:="Contact Phone")> _
        Public Property ContactPhone As Object
    
        <Display(Name:="Contact Email")> _
        Public Property ContactEMail As Object
    
        <Display(Name:="Client Is Deleted")> _
        Public Property isDeleted As Object
    
        <DisplayFormat(ApplyFormatInEditMode:=False, DataFormatString:="yyyy-MM-dd")> _
        <Display(Name:="Date Created")> _
        Public Property _dtCreated As Object
    
        <DisplayFormat(ApplyFormatInEditMode:=False, DataFormatString:="yyyy-MM-dd")> _
        <Display(Name:="Date Modified")> _
        Public Property _dtModified As Object
    
    
    End Class
    

    I've tried including the namespace of my project. This didn't work. I tried without the Namespace. Still not using the class.

    Initially tried with setting my

       DefaultModel.RegisterContext(GetType( _
                HCCWebServiceMetaDataDBEntities), _
                New ContextConfiguration() With {.ScaffoldAllTables = True})

    to False but then I got message

     If visibleTables.Count = 0 Then
                Throw New InvalidOperationException("There are no accessible tables. " &
                    "Make sure that at least one data model is registered in Global.asax " &
                    "and scaffolding is enabled or implement custom pages.")
            End If

     

    So 1: How do I get my override class entity recognized? And get it to override the built in entity?

    2: Will this class extend to my insert, edit and delete pages and not just the list and list details pages in my PageTemplates?

    3: My GUID is defaulted to NEWID() in SQL. This shouldn't be an issue that it will request it for the insert? Because if I try and insert it currently with the partial class not working and it defaulting to its build in class it obviously shows the field and it tries and validates it asking for a GUID - which it isn't supposed to as this is default value of NEWID in SQL.

    Please help. This is sooo frustration.

     

    This is one of the sites I looked at: http://www.codeproject.com/Articles/377291/An-Introduction-to-ASP-NET-Dynamic-Data-from-a-Beg

    Another site: https://www.microsoftpressstore.com/articles/article.aspx?p=2225081&seqNum=4

     

    Wednesday, January 14, 2015 10:09 PM

Answers

  • User-330204900 posted

    first of are you using a Site project or a Web Application Project? this makes a difference also I would not use the App_Data folder for this as asp.net has special uses for the special folders it created, I always use a Models folder for my edmx files :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 15, 2015 4:17 PM

All replies

  • User-330204900 posted

    first of are you using a Site project or a Web Application Project? this makes a difference also I would not use the App_Data folder for this as asp.net has special uses for the special folders it created, I always use a Models folder for my edmx files :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 15, 2015 4:17 PM
  • User-1084196641 posted

    Hi

    I use a Web Application Project.

    Thanks. Started from scratch. Kept the class and entity model in the base project. All works now.

    Thursday, January 15, 2015 7:58 PM
  • User-330204900 posted

    OK then create a Models folder it's best to not use the Asp.net special folders for anything other than its purpose, and here is a sample of how I do my buddy/metadata classes:

    [MetadataType(typeof(RepairType.Metadata))]
    public partial class RepairType
    {
    	internal sealed class Metadata
    	{
    		public int Id { get; set; }
    		[Display(Name = "User Name")]
    		public String Name{ get; set; }
    	}
    }

    VB.Net

    <MetadataType(GetType(RepairType.Metadata))> _
    Public Partial Class RepairType
    	Friend NotInheritable Class Metadata
    		Public Property Id() As Integer
    			Get
    				Return m_Id
    			End Get
    			Set
    				m_Id = Value
    			End Set
    		End Property
    		Private m_Id As Integer
    		<Display(Name := "User Name")> _
    		Public Property Name() As [String]
    			Get
    				Return m_Name
    			End Get
    			Set
    				m_Name = Value
    			End Set
    		End Property
    		Private m_Name As [String]
    	End Class
    End Class

    I used an online C# to VB.Net conversion tool to get the VB

    Friday, January 16, 2015 6:15 AM