No metadata has been registered for class

3 posts, 0 answers
  1. Brian
    Brian avatar
    2 posts
    Member since:
    Dec 2012

    Posted 02 Feb 2013 Link to this post

    Alright, I've been pulling my hair out over this for nearly 3 days, and I'm about to scrap everything and abandon OpenAccess unless someone can point me in the right direction.

    I've got an OpenAccess library that is connected to a SQL Azure database, and the compiled assembly is referenced in an MVC4 website. Pretty straightforward. But regardless how I create the OA entities, I always end up with this error:

    No metadata has been registered for class 'DummyProject.Data.Models.DummyModel, DummyProject.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. (This usually indicates, that either this class is not declared persistent or it is declared persistent but not enhanced.)

    I've tried creating the classes several ways:

    1. OpenAccess Class Library, XML Mapping
    2. OpenAccess Class Library, Attribute Mapping
    3. OpenAccess Class Library, Fluent Mapping
    4. OpenAccess Fluent Library (Code Only)

    Using the first 3 methods, I generated classes from an existing Azure DB schema. When I wasted enough time, I ignored the database and attempted the 4th method as code-first. They all eventually failed with this error. For each attempt, I completely deleted the old class library and created a new project, to avoid any "leftovers" causing problems.

    I've tried just about every solution I could find, but nothing has worked:

    <Import Condition="Exists('$(MSBuildExtensionsPath)\OpenAccess.targets')" Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />

    Yes, that has been automatically added to my project. I tried every configuration/tweak from this thread:

    http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/no-metadata-has-been-registered-for-class-locationsmodule-model-locationitem

    I've gone about as basic as I can get and still receive the error. Here's my dummy model:

    public class DummyModel
    {
        public int DummyId { get; set; }
        public string DummyText { get; set; }
    }

    My DataContext:

    public partial class DummyDataContext : OpenAccessContext
        {
            static MetadataContainer metadataContainer = new DummyMetadataSource().GetModel();
            static BackendConfiguration backendConfiguration = new BackendConfiguration()
            {
                Backend = "Azure",
                ProviderName = "System.Data.SqlClient"
            };
     
            private const string DbConnection = "DefaultConnection";
     
            public DummyDataContext ()
                : base(DbConnection, backendConfiguration, metadataContainer)
            {
     
            }
     
            public IQueryable<DummyModel> Dummies
            {
                get
                {
                    return this.GetAll<DummyModel>();
                }
            }
     
            public void UpdateSchema()
            {
                var handler = this.GetSchemaHandler();
                string script = null;
                try
                {
                    script = handler.CreateUpdateDDLScript(null);
                }
                catch
                {
                    bool throwException = false;
                    try
                    {
                        handler.CreateDatabase();
                        script = handler.CreateDDLScript();
                    }
                    catch
                    {
                        throwException = true;
                    }
                    if (throwException)
                        throw;
                }
     
                if (string.IsNullOrEmpty(script) == false)
                {
                    handler.ExecuteDDLScript(script);
                }
            }
        }

    And lastly, my MetadataSource:

    public class DummyDataMetadataSource : FluentMetadataSource
        {
            protected override IList<MappingConfiguration> PrepareMapping()
            {
                List<MappingConfiguration> configurations = new List<MappingConfiguration>();
     
                MappingConfiguration<DummyModel> dummyConfiguration = new MappingConfiguration<DummyModel>();
                dummyConfiguration .MapType().ToTable("Dummies");
                dummyConfiguration .HasProperty(x => x.DummyId).IsIdentity();
     
                configurations.Add(dummyConfiguration );
     
                return configurations;
            }
        }

    All that compiles fine, but runtime throws the error. I'm developing locally on the Azure SDK, so this is all running on the Azure Fabric Compute/Storage emulators, but the Azure DB connection is pointed to a live Azure DB.

    Can anybody help? God help me, I don't want to revert to Entity Framework, but I'm running out of time an options.
  2. Brian
    Brian avatar
    2 posts
    Member since:
    Dec 2012

    Posted 03 Feb 2013 Link to this post

    Solved. For anyone else who has seemingly tried everything else, uninstalling and reinstalling OpenAccess seemed to fix the problem.

    That old "IT Crowd" adage holds true: Have you tried turning it off and on again?
  3. DevCraft banner
  4. Trevor
    Trevor avatar
    7 posts
    Member since:
    Jul 2012

    Posted 30 Mar in reply to Brian Link to this post

    Unbelievable.  After all the time I spent on this problem, this was the fix for mine as well....
Back to Top