开发者

Mapping Exception. No persister for "Entity"

Hy guys,

I've searched all over the web and didn't find a solution to this problem...

This is my entity...

    public class Pedido : IKeyed<int>
{
    public virtual int Id { get; private set; }
    public virtual string Assunto { get; set; }
    public virtual string Data { get; set; }
    public virtual Categoria Categoria{ get; set; }
    public virtual Modulo Modulo { get; set; }
    public virtual Pessoa Pessoa { get; set; }
    public virtual Site Site { get; set; }
    public virtual Situacao Situacao { get; set; }
    public virtual IList<Interacao> Interacao { get; set; }

    public Pedido()
    {
        Interacao = new List<Interacao>();
    }

    public virtual void addCategoria(Categoria categoria)
    {
        Categoria=categoria;
    }

    public virtual void addInteracao(Interacao interacao)
    {
        interacao.Pedido = this;
        Interacao.Add( interacao );
    }

}

The classMap...

    public class PedidoMap : ClassMap<开发者_开发百科;Pedido>
{
    PedidoMap()
    {
        Table( "z1_pedido" );
        Id( x => x.Id );
        Map( x => x.Assunto );
        Map( x => x.Data );
        References( x => x.Categoria ).Column( "Id" );
        References( x => x.Modulo ).Column( "Id" );
        References( x => x.Pessoa ).Column( "Id" );
        References( x => x.Site ).Column( "Id" );
        References( x => x.Situacao ).Column( "Id" );
        HasMany( x => x.Interacao ).LazyLoad().Inverse().Cascade.All();

    }
}

My Repository:

public class Repository<T> : NHibernateContext, IKeyedRepository<int, T> where T : class, IKeyed<int>
{
    private readonly ISession _session;

    public Repository(ISession session)
    {
        _session = session;
    }

    public bool Add(T entity)
    {
        _session.Save( entity ); "<-- Here's where the debug stops and display the error"
        return true;
    }

The test method:

                UnitOfWork unitOfWork = new UnitOfWork( helper.SessionFactory );

            Repository<Pedido> repository = new Repository<Pedido>( unitOfWork.Session );

            Pedido pedido = CreatePedido( string.Format( "Pedido {0}", i + 1 ), 10 );
            repository.Add( pedido ); "<-- Call the Repository."

            unitOfWork.Commit();
        }

Please Guys... helpe me!

Thks.


You need to configure FluentNhibernate to look for mappings in the assembly where the PedidoMap class resides. Something like this:

        var fluentConfig = Fluently.Configure();
        fluentConfig.Mappings(m => 
            m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));
        var cfg = fluentConfig.BuildConfiguration();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜