This question is locked. New answers and comments are not allowed.
Hi my project currently works with EntityFramework to provide the database access and works to a degree. I am looking at converting it over to OpenAccess but am running into some issues.
My project is separated into multiple assemblies, Project.Core and Project.DAL being the relevant modules, which are accessed from Project.Web. In the Core project I have all my base entities defined, like so:
In the DAL project I have my mappings defined like so:
The problem I then run into is an exception at runtime when creating the schema:
"No metadata has been registered for class 'Project.Core.Domain.Global.Country, Project.Core, 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:/Data/Project/Project.Web/bin/Project.Core.DLL.)
The Core, DAL, and Web modules all have in their respective csproj the line:
<Import Condition="Exists('$(MSBuildExtensionsPath)\OpenAccess.targets')" Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />
After some research it would seem the Enhancer isn't running for certain modules, or the separation of the modules may be an issue. Taking the Country.cs file into the DAL module does resolve the issue, which then will complain about the other Entity objects that have not been moved.
I am unsure how to move forward with regards to resolving this issue. I would like to keep the separation of modules in my project. Any input towards a solution is appreciated!
My project is separated into multiple assemblies, Project.Core and Project.DAL being the relevant modules, which are accessed from Project.Web. In the Core project I have all my base entities defined, like so:
using System.Collections.Generic;using Project.Core.Domain.Localization;namespace Project.Core.Domain.Global{ public class Country : IEntity, ILocalizedEntity { private readonly IList<StateProvince> stateProvinces = new List<StateProvince>(); public virtual string Name { get; set; } public virtual string TwoLetterIsoCode { get; set; } public virtual string ThreeLetterIsoCode { get; set; } public virtual int NumericIsoCode { get; set; } public virtual bool IsPublished { get; set; } public virtual int DisplayOrder { get; set; } public virtual IList<StateProvince> StateProvinces { get { return stateProvinces; } } #region IEntity Members public virtual long Id { get; set; } #endregion }}In the DAL project I have my mappings defined like so:
using Project.Core.Domain.Global;using Telerik.OpenAccess.Metadata;using Telerik.OpenAccess.Metadata.Fluent;namespace Project.DAL.Mapping.Global{ public class CountryConfiguration : MappingConfiguration<Country>, IDatabaseMap { public CountryConfiguration() { MapType(x => new { IsPublished = x.IsPublished, Name = x.Name, NumericIsoCode = x.NumericIsoCode, ThreeLetterIsoCode = x.ThreeLetterIsoCode, TwoLetterIsoCode = x.TwoLetterIsoCode, DisplayOrder = x.DisplayOrder }).ToTable("Country"); HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc); } }}using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using Telerik.OpenAccess.Metadata.Fluent;namespace Project.DAL.Mapping{ public class ProjectMetadataSource : FluentMetadataSource { private readonly IList<MappingConfiguration> configurations = new List<MappingConfiguration>(); protected override IList<MappingConfiguration> PrepareMapping() { var assemblies = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies()); foreach (var assembly in assemblies) { var stuff = assembly.GetTypes().Where(type => !string.IsNullOrEmpty(type.Namespace)).Where ( type => type.BaseType != null && type.GetInterfaces().Contains(typeof (IDatabaseMap))); foreach (var type in stuff) { var map = Activator.CreateInstance(type) as MappingConfiguration; configurations.Add(map); } } return configurations; } }}The problem I then run into is an exception at runtime when creating the schema:
"No metadata has been registered for class 'Project.Core.Domain.Global.Country, Project.Core, 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:/Data/Project/Project.Web/bin/Project.Core.DLL.)
The Core, DAL, and Web modules all have in their respective csproj the line:
<Import Condition="Exists('$(MSBuildExtensionsPath)\OpenAccess.targets')" Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />
After some research it would seem the Enhancer isn't running for certain modules, or the separation of the modules may be an issue. Taking the Country.cs file into the DAL module does resolve the issue, which then will complain about the other Entity objects that have not been moved.
I am unsure how to move forward with regards to resolving this issue. I would like to keep the separation of modules in my project. Any input towards a solution is appreciated!