views:

122

answers:

1

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;

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 Versions { get; set; }

    public Entity()
    {
        //Versions = new List<EntityVersion>();
    }

} }

A: 

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))
Darin Dimitrov
Hi Darin, thanks for your answer. Maybe I am missing the entire point of the Entity type being passed in the first line:What does the AddAssembly<Entity> represent / is used for? :)m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>).Where(t => t.Namespace == "Modules.Business.Entities") )
M. Schopman
It means map all types that are defined in the assembly in which the Entity type is defined (hope it makes sense).
Darin Dimitrov
It doesn't mean map the Entity type.
Darin Dimitrov

related questions