I have an issue with Fluent NHibernate where automapping isn't picking up the entitites in my web project DLL. Normally I store all entities in a separate assembly and this has always worked. However, this project is rather small so I'm trying to keep it all in one project. However, when I call AutoMap.AssemblyOf<MyEntityType>()
, no mappings are created. I'm wondering if this is because the entity lives in the web project assembly which gets loaded from Temporary ASP.NET files folder and not the actual folder where the project lives on disk. Is it a permissions issue or something? I'm not sure where to start debugging...
Example entity:
namespace MyProject.Entities
{
public class Letter : EntityBase
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public string Country { get; set; }
public string Interest { get; set; }
public string Section1 { get; set; }
public string Section2 { get; set; }
public string Section3 { get; set; }
public string LetterText { get; set; }
public int StepNumber { get; set; }
}
}
Relevant boostrap code:
private static ISessionFactory GetSessionFactory()
{
var database = MsSqlConfiguration.MsSql2005
.ConnectionString(Configuration.ConnectionString)
.DefaultSchema(DEFAULT_SCHEMA)
.AdoNetBatchSize(BATCH_SIZE);
var mappings = AutoMap.AssemblyOf<Letter>()
.Where(x => x.GetType() == typeof(Letter))
.Conventions.Add
(
ConventionBuilder.Id.Always(x =>
x.GeneratedBy.HiLo(HILO_TABLE, HILO_COLUMN, HILO_MAX_LO)),
ConventionBuilder.HasMany.Always(x => x.Cascade.AllDeleteOrphan()),
Table.Is(o => Inflector.Pluralize(o.EntityType.Name)),
PrimaryKey.Name.Is(o => "Id"),
ForeignKey.EndsWith("Id"),
DefaultLazy.Never(),
DefaultCascade.All()
);
// ...
I changed the Where clause to look for the specific type instead of the namespace, but that didn't work either. the mappings object still ends up empty.
Also, the EntityBase class is an empty class but for one property 'Id' which is inherited by all entities.
EDIT: I moved the entities to their own assembly and am still having the problem, so it's not related to the location of the web project assembly. I'm still quite lost on this one. :(
virtual
to all the properties? NHibernate requires all properties to bevirtual
. – Daniel T.