Question

I add a new class to my domain but this time fluently doesn't map to the database

this is the class

namespace FClinic.Domain.Entities.Tenants
{
    using System;
    using Core;

    public class Tenant : BaseTenant
    {
        public virtual DateTime UsageUntil { get; set; }
    }

    public abstract class BaseTenant : Entity
    {
        public virtual string Name { get; set; }
        public virtual string Key { get; set; }
    }
}

the fluently configuration is this one:

public class FclinicConfiguration : DefaultAutomappingConfiguration
{
    public override bool ShouldMap(Type type)
    {
        if (type.Name.Contains("<>c__DisplayClass"))
            return false;
        if (type.Name == "CancelationResult")
            return false;

        return type.Namespace != null && type.Namespace.StartsWith("FClinic.Domain.Entities") && !type.IsValueType;
    }

    public override bool ShouldMap(FluentNHibernate.Member member)
    {
        if (!member.CanWrite)
            return false;

        return base.ShouldMap(member);
    }

    public override bool IsComponent(Type type)
    {
        if (type == typeof(ContactoEmergencia))
        {
            return true;
        }            

        return base.IsComponent(type);
    }
}

As yo can see the Tenant entity namespace start with "FClinic.Domain.Entities" and match the other conditions

    type.Namespace != null
 && type.Namespace.StartsWith("FClinic.Domain.Entities")
 && !type.IsValueType;

in fact the method ShouldMap(Type type) return true for the Tenant Type but when i check the Database generated it include all the other classes except this one

Any Idea?

Fluently configuration

_sessionFactory = Fluently.Configure()              
 .Database(MsSqlConfiguration.MsSql2008.ConnectionString(config.ConnectionString))
 .Mappings(m => m.AutoMappings
   .Add(AutoMap.AssemblyOf<Administrador>(new FclinicConfiguration())
   .UseOverridesFromAssemblyOf<UsuarioMappingOverride>()
   .IncludeBase<TreatmentBaseTemplate>()
   .Conventions.Add<GuidIdentity>()
   .Conventions.Add<ForeignKeyNameConvention>()
   .Conventions.Add<ReferenceConvention>()
   .Conventions.Add<DecimalConvention>()))
.ExposeConfiguration(c => new SchemaUpdate(c).Execute(false, true))
.BuildSessionFactory();
Was it helpful?

Solution

the problem here is not NHibernate or Fluently, as you can notice the class BaseTenant has a property named Key

public abstract class BaseTenant : Entity
{
    public virtual string Name { get; set; }
    public virtual string Key { get; set; }
}

this will raise a conflict at database generation because this is SQL Server reserve word so i just rename the property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top