映射异常。没有“实体”的持久化器
大家好,
我在整个网络上进行了搜索,但没有找到这个问题的解决方案...
这是我的实体...
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要配置 FluentNhibernate 来查找程序集中的映射,其中PedidoMap 类驻留。像这样的东西:
You need to configure FluentNhibernate to look for mappings in the assembly where the PedidoMap class resides. Something like this: