映射异常。没有“实体”的持久化器

发布于 2024-10-18 17:30:04 字数 2416 浏览 1 评论 0原文

大家好,

我在整个网络上进行了搜索,但没有找到这个问题的解决方案...

这是我的实体...

    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 );
    }

}

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();

    }
}

我的存储库:

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;
    }

测试方法:

                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();
        }

请大家...帮助我!

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2024-10-25 17:30:04

您需要配置 FluentNhibernate 来查找程序集中的映射,其中PedidoMap 类驻留。像这样的东西:

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文