No metadata has been registered for class - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

No metadata has been registered for class

  • No metadata has been registered for class
  • I am new to Sitefinity. I installed a trial. I am trying to run as simple data access operation within a custom widget. (see code below.)

    I started with a standard SitefinityWebApp project which was generated from the installed Sitefinity Project Manager. I have not added any references or Nuget packages. I can see that the project includes references to Telerik.OpenAccess.dll (version2015.3.926.1) plus other OpenAccess DLLs.

    I added a "CustomTypes" folder, and created custom model, MetaDataDataProvider, FluentMetaDataSource, and Context classes, similar to those in your "Testimonials" sample application.

    When I try to install the widget onto a page, the code gets to the following line in the PersonContext class:

        return OpenAccessConnection.GetContext(new PersonMetaDataProvider(), "Sitefinity") as PersonContext;

    I get the following error:

    No metadata has been registered for class 'SitefinityWebApp.CustomTypes.PersonType, SitefinityWebApp, Version=8.2.5900.0, Culture=neutral, PublicKeyToken=null'. (This usually indicates, that either this class is not declared persistent or it is declared persistent but not enhanced. The class was loaded from file:///C:/Program Files (x86)/Telerik/Sitefinity/Projects/TestSandbox/bin/SitefinityWebApp.DLL.)

    I have looked through the forum posts, and tried some of the previous suggestions. Can you please advise?

     

    --------------------

    public class PersonContext : SitefinityOAContext
       
            public PersonContext(SitefinityOAContext fromContext) 
                : base(fromContext)
           
           

            public PersonContext(string connectionString, BackendConfiguration backendConfiguration, MetadataContainer metadataContainer) 
                : base(connectionString, backendConfiguration, metadataContainer)
           
           

            public static PersonContext Get()
           
                return OpenAccessConnection.GetContext(new PersonMetaDataProvider(), "Sitefinity") as PersonContext;
           

            /// <summary>
            /// Gets an IQueryable result of all persons.
            /// </summary>
            public IQueryable<PersonType> Persons
           
                get
               
                    return this.GetAll<PersonType>();
               
           

            public PersonType CreatePersonType()
           
                return this.CreatePersonType(new Guid());
           

            public PersonType CreatePersonType(Guid id)
           
                if (id == Guid.Empty)
                    throw new ArgumentException("Id cannot be an Empty Guid");

                var item = new PersonType(id);
                this.Add(item);
                return item;
           

            public PersonType GetPersonType(Guid id)
           
                if (id == Guid.Empty)
                    throw new ArgumentException("Id cannot be an Empty Guid");

                PersonType item = this.GetItemById<PersonType>(id.ToString());
                return item;
           

            public void DeletePerson(PersonType item)
           
                this.Delete(item);
           

            public void AddPerson(PersonType item)
           
                this.Add(item);
                   
            
            public void AddPersons(IEnumerable<PersonType> items)
           
                this.Add(items);
           
     ----------

        public class PersonFluentMetDataSource : FluentMetadataSource
       
            protected override IList<MappingConfiguration> PrepareMapping()
           
                var mappings = new List<MappingConfiguration>();
                var personMapping = this.MapPersonsTable();
                mappings.Add(personMapping);
                return mappings;
           

            private MappingConfiguration<PersonType> MapPersonsTable()
           
                var personTypeMapping = new MappingConfiguration<PersonType>();
                personTypeMapping.MapType().ToTable("sf_Persons");

                personTypeMapping.HasProperty(x => x.Id).HasFieldName("id").IsIdentity().IsNotNullable();
                personTypeMapping.HasProperty(t => t.Title).HasLength(255).IsNotNullable();
                personTypeMapping.HasProperty(t => t.FirstName).HasLength(255).IsNotNullable();
                personTypeMapping.HasProperty(t => t.LastName).HasLength(255).IsNotNullable();
                personTypeMapping.HasProperty(t => t.DateOfBirth).IsNotNullable();
                //personTypeMapping.HasProperty(x => x.LastModified).ToColumn("last_modified").IsCalculatedOn(Telerik.OpenAccess.Metadata.DateTimeAutosetMode.InsertAndUpdate).IsNullable();
                //personTypeMapping.HasProperty(x => x.ApplicationName).HasFieldName("appName").ToColumn("app_name").HasLength(50).IsNullable();
                personTypeMapping.HasProperty(x => x.Title).IsNullable();

                return personTypeMapping;
           
       

    ------------------

        public class PersonMetaDataProvider : IOpenAccessMetadataProvider, IOpenAccessCustomContextProvider
       
            public MetadataSource GetMetaDataSource(IDatabaseMappingContext context)
           
                return new PersonFluentMetDataSource();
           

            public string ModuleName
           
                get return null;
           

            public SitefinityOAContext GetContext(string connectionString, BackendConfiguration backendConfiguration,
                MetadataContainer metadataContainer)
           
                return new PersonContext(connectionString, backendConfiguration, metadataContainer);
           
       

    ----------------------

        [Persistent(IdentityField = "Id")]
        public class PersonType 
       
            // backing variables for IDataItem properties
            private Guid id;
            //private string appName;
            //private object transaction;
            //private object provider;
            //private DateTime lastModified;

            // backing variables for my Person properties
            private string title;
            private string firstName;
            private string lastName;
            private DateTime dateOfBirth;

            public PersonType()
           
                
           

            public PersonType(Guid id)
           
                this.id = id;
           

            #region My custom properties

            public string Title
           
                get
               
                    return this.title;
               
                set
               
                    this.title = value;
               
           

            public string FirstName
           
                get
               
                    return this.firstName;
               
                set
               
                    this.firstName = value;
               
           

            public string LastName
           
                get
               
                    return this.lastName;
               
                set
               
                    this.lastName = value;
               
           

            public DateTime DateOfBirth
           
                get return this.dateOfBirth;
                set this.dateOfBirth = value;
           

            public Guid Id
           
                get
               
                    return this.id;
               
                set
               
                    this.id = value;
               
           
     
    #endregion

       

    -------------------------

       public partial class PersonWidget : System.Web.UI.UserControl
       
            protected void Page_Load(object sender, EventArgs e)
           
                Label1.Text = "Hello Andy";

                PersonContext context = PersonContext.Get();
                Guid newGuid = new Guid();
                
                PersonType person = new PersonType(newGuid);
                person.Title = "Mr.";
                person.FirstName = "Fred";
                person.LastName = "Flintstone";
                person.DateOfBirth = DateTime.Today.AddYears(-45);

                context.AddPerson(person);
                context.SaveChanges();

                IQueryable<PersonType> personTypes = context.Persons;
                var personCount = personTypes.Count();

                Label1.Text = string.Format("There are 0 people in the database", personCount);

                context.DeletePerson(person);
     
           

  • Andy,

    I know this doesn't address the actual question you asked but, have you had a look at module builder? That's typically what's used when someone needs to build out a custom type. You don't have to mess with code at all and still get an api for custom data access if needed.

    If you *do* need code-level control over the actual content type, Sitefinity Thunder is useful for generating what's necessary.

  • I followed your advice and integrated the Telerik.DataAccess.Fluent nuget package into my project and tried to build it. Now, it will not build. 
    I get the following message:

    The "OpenAccessEnhancer" task could not be loaded from the assembly C:\Program Files %28x86%29\Telerik\Sitefinity\Projects\TestSandbox\\packages\Telerik.DataAccess.Fluent.2016.1.224.1\tools\enhancer\enhancer.exe. Could not load file or assembly 'file:///C:\Program Files %28x86%29\Telerik\Sitefinity\Projects\TestSandbox\packages\Telerik.DataAccess.Fluent.2016.1.224.1\tools\enhancer\enhancer.exe' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

    I can see that the  enhancer.exe file is at the stated file path. (I'm not sure about the double slash before the packages folder in the link listed in the error message, though.)

    Can you please advise?
  • Hello,

    The error you are getting is most likely caused by the lack of the OpenAccessEnhancer in your project. Try installing the Telerik.DataAccess.Fluent nuget package in your project and build it.

    Regards,
    Velizar Bishurov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Hello,

    Please refer to the following KB article for information how to resolve the issue: http://www.sitefinity.com/developer-network/knowledge-base/details/the-openaccessenhancer-task-could-not-be-loaded-error-on-build-when-using-nuget-packages

    Regards,
    Velizar Bishurov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • I saw that post before submitting this question.

    The project was created by and is managed by the Sitefinity Project Manager. If I move the while project to save a few characters in the file paths, then I lose the ability to mange it through the Project Manager.

    This is a vanilla project created by the Project Manager and Thunder. I have done nothing unusual here. Why would those products set up auto generated projects that will not work properly?

  • Hello,

    To continue investigating the problem please open a support ticket so we can provide with a way to get a copy of the project to us and investigate the issue on our end.

    Regards,
    Velizar Bishurov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • The error you are getting is most likely caused by the lack of the OpenAccessEnhancer in your project.
  • Sorry, not sure what you mean. The enhancer appears to be an .exe. Can you please expand? How do I incorporate an OpenAccessEnhancer into the project? And how do I configure and reference it within the project?