I am a complete beginner with Fluent and I am running into an issue which is probably my own fault.
I have a namespace containing 3 classes. Entity, EntityVersion and Property. No inheritance involved between the classes.
I try to only map the Entity class but what happens is that all classes in the namespace are being mapped. What am I doing wrong here?
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2005
.ConnectionString("Data Source=MSCHOPMAN\\SQLEXPRESS;Initial Catalog=framework;Integrated Security=SSPI"))
.Mappings(m =>
{
m.AutoMappings.Add(
AutoMap.AssemblyOf<Entity>()
//.IgnoreBase<Entity>()
.Where(t => t.Namespace == "Modules.Business.Entities")
)
.ExportTo("c:\\temp");
}
)
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
And the Entity class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Modules.Data;
开发者_JS百科namespace Modules.Business.Entities
{
public class Entity
{
public virtual int Id { get; set; }
public virtual int ParentId { get; set; }
public virtual int TypeId { get; set; }
//public virtual IList<EntityVersion> Versions { get; set; }
public Entity()
{
//Versions = new List<EntityVersion>();
}
}
}
This line:
.Where(t => t.Namespace == "Modules.Business.Entities")
instructs FluentNHibernate to map all objects inside the Modules.Business.Entities
namespace. If you want to map only a particular type you could try specifying its name:
.Where(t => t == typeof(Entity))
精彩评论