开发者

AutoMap.AssemblyOf maps entire namespace

开发者 https://www.devze.com 2022-12-09 13:57 出处:网络
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 involve

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))
0

精彩评论

暂无评论...
验证码 换一张
取 消