This is a migrated thread and some comments may be shown as answers.

Is it possible to add/include an external class to Fluent Model?

7 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cubski
Top achievements
Rank 1
Cubski asked on 11 Mar 2013, 07:57 PM
I'm getting this error "No metadata has been registered for class 'OpenAccessTest.Domain.Category, OpenAccessTest.Domain, 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. The class was loaded from file:///c:/users/carl/documents/visual studio 2012/Projects/OpenAccessTest/OpenAccessTest/bin/Debug/OpenAccessTest.Domain.DLL.)"

This is when I added an external "Category" class to my Fluent Model. The Category class is from a different class project in the same solution. I already made sure that the OpenAccess Enhancer was included in the project yet I always get the same error. So my question is, is it possible to add external class to fluent models?

OpenAccessContext code:

namespace OpenAccessTest   
{
    using System.Linq;
 
    using OpenAccessTest.Domain;
 
    using Telerik.OpenAccess;
    using Telerik.OpenAccess.Metadata;
 
    public partial class FluentModel : OpenAccessContext
    {
        private static string connectionStringName = @"Server=localhost;Port=3306;Database=testdb;Uid=root;Pwd=batsoy;";
             
        private static BackendConfiguration backend = GetBackendConfiguration();
         
        private static MetadataSource metadataSource = new FluentModelMetadataSource();
     
        public FluentModel()
            : base(connectionStringName, backend, metadataSource)
        {
             
        }
             
        public static BackendConfiguration GetBackendConfiguration()
        {
            var backend = new BackendConfiguration
                          {
                              Backend = "MySql",
                              ProviderName = "MySql.Data.MySqlClient"
                          };
            return backend;
        }
 
        public IQueryable<Category> Categories
        {
            get
            {
                return this.GetAll<Category>();
            }
        }
    }
}

Mapping code:

namespace OpenAccessTest
{
    using System.Collections.Generic;
 
    using OpenAccessTest.Domain;
 
    using Telerik.OpenAccess.Metadata;
    using Telerik.OpenAccess.Metadata.Fluent;
 
    public partial class FluentModelMetadataSource : FluentMetadataSource
    {
        protected override IList<MappingConfiguration> PrepareMapping()
        {
            var mappingConfigurations = new List<MappingConfiguration>();
 
            var categoryConfig = new MappingConfiguration<Category>();
            categoryConfig.MapType().UseDefaultMap().ToTable("Category");
 
            mappingConfigurations.Add(categoryConfig);
             
            return mappingConfigurations;
        }
         
        protected override void SetContainerSettings(MetadataContainer container)
        {
            container.NameGenerator.RemoveCamelCase = false;
            container.NameGenerator.SourceStrategy = NamingSourceStrategy.Property;
        }
    }
}

Category class code:

namespace OpenAccessTest.Domain
{
    public class Category
    {
        public int Id { get; set; }
 
        public string Name { get; set; }
    }
}

Thank you in advance.

7 Answers, 1 is accepted

Sort by
0
Cubski
Top achievements
Rank 1
answered on 12 Mar 2013, 10:51 AM
Sorry to bump this post but I spent hours trying to make it work to no avail. Am I correct to assume that it isn't possible?
0
Accepted
Kaloyan Nikolov
Telerik team
answered on 12 Mar 2013, 11:35 AM
Hi Cubski,

The OpenAccess Enhancer works only with classes placed in one and the same project with the FluentMetadataSource class. If you use a class from another project even if the Enhancer's target is added in that project the class will not be enhanced. As a result you get "No metadata has been registered..."  exception during runtime. 

The external class is not enhanced during the build because the Enhancer needs the metadata located in the FluentMetadataSource class, which in your case is located in another project. 

If it is feasible, you can try to restructure your projects in such way that you place all data classes and the FluentMetadataSource class together in a project. 

If you have any additional questions I will be glad to help you.

All the best,
Kaloyan Nikolov
the Telerik team
OpenAccess ORM Q1 2013 is out featuring Multi-Diagrams, Persistent Data Stream Support and much more. Check out all of the latest highlights.
0
Cubski
Top achievements
Rank 1
answered on 12 Mar 2013, 12:00 PM
Hi Kaloyan,

Thanks for the clear explanation. By the way, is this something that the OA team consider adding in future versions? It would be nice if we can use classes from separate projects or third party libraries with minimal effort. I'll restructure my project for the meantime. 

Best Regards.
0
Kaloyan Nikolov
Telerik team
answered on 12 Mar 2013, 05:07 PM
Hello Cubski,

For the time being we don't have immediate plans to implement this behavior. Such a feature could lead to problems with the build order. 

Let's imagine the following project structure:

EntitiesClasses project files:
- Book.cs
- Category.cs

OpenAccess.DAL project:
  References
   - EntitiesClasses 
- MyLibraryFluentMetadataSource

If we have this project structure we should enhance the EntitiesClasses project, to be able to do it we should first discover where that project is referenced and check if there is a FluentMetadataSource which contains metadata for the classes. To do so we should first compile the OpenAccess.DAL project but we cannot do it before we compile the EntitiesClasses project because of the reference to it, then we start from the beginning. In other words this is a build order cycle we cannot handle.

Also it isn't possible to enhance third party libraries  because the enhancement process is a post-build action in the generated code. We cannot do that for third party assemblies compiled outside the solution because they could be signed. 

What we can do is to define an alternative way how to handle situations like this without the enhancer. If you are interested in such feature we can create a new feature request on our feedback portal so that you and other people can vote for it, raising its priority on our list. 

Thank you for your deep interest in our product.

Kind regards,
Kaloyan Nikolov
the Telerik team
OpenAccess ORM Q1 2013 is out featuring Multi-Diagrams, Persistent Data Stream Support and much more. Check out all of the latest highlights.
0
Cubski
Top achievements
Rank 1
answered on 12 Mar 2013, 05:28 PM
Hi Kaloyan,

Again thanks for the detailed reply. I was able to make it work on my project after a couple of modifications in certain parts of the code base, however, having another way that doesn't use OA Enhancer would be ideal. It would make OA more straightforward to use as well as still use it certain scenarios where I have to use classes from a separate project or from an external library.

Thanks again.
0
Cubski
Top achievements
Rank 1
answered on 12 Mar 2013, 05:36 PM
Kindly create the feature request for me and the link. Thanks.
0
Kaloyan Nikolov
Telerik team
answered on 15 Mar 2013, 04:14 PM
Hi Cubski,

Here is the feature request we talked about: Persistence Capabilities without the Enhancer Tool. You can be the first to vote for it. 

Do not hesitate to get back to us for any feature requests that can make OpenAccess ORM more suitable for your needs.

All the best,
Kaloyan Nikolov
the Telerik team
OpenAccess ORM Q1 2013 is out featuring Multi-Diagrams, Persistent Data Stream Support and much more. Check out all of the latest highlights.
Tags
General Discussions
Asked by
Cubski
Top achievements
Rank 1
Answers by
Cubski
Top achievements
Rank 1
Kaloyan Nikolov
Telerik team
Share this question
or