У меня проблема здесь.
Как вы можете видеть из кода ниже, у меня есть 2 объекта: "Pedidos" и "Категория".«Pedido» записано ОДНО «Категорией».
Я выполнил тестовый метод, и Pedidos, и Категория хранятся в БД.Отлично!
Но ...... Поле "Pedido.Categoria" пусто.Куда я иду не так?
СУЩНОСТИ:
public class Categoria : IKeyed<int>{
public virtual int Id { get; set; }
public virtual string Nome { get; set; }};
public class Pedido : IKeyed<int>{
public virtual int Id { get; set; }
public virtual string Assunto { get; set; }
public virtual Categoria Categoria { get; set; }
public virtual IList<Interacao> Interacao { get; set; }
public virtual void addCategoria(Categoria categoria)
{Categoria = categoria;}
};
КАРТИНГИ:
public class PedidoMap : ClassMap<Pedido>
{
PedidoMap()
{
Table( "z1_pedido" );
Id( x => x.Id );
Map( x => x.Assunto );
References( x => x.Categoria ).Column( "id" );
HasMany( x => x.Interacao ).LazyLoad().Inverse().Cascade.All();
}
}
public class CategoriaMap : ClassMap<Categoria>
{
CategoriaMap()
{
Table( "z1_categoria" );
Id( x => x.Id );
Map( x => x.Nome ).Column("nome");
}
}
МЕТОД ТЕСТА:
public void AddTest()
{
Repository<Pedido> repository = new Repository<Pedido>( unitOfWork.Session );
Repository<Categoria> catRepo = new Repository<Categoria>( unitOfWork.Session );
Categoria cat = new Categoria
{
Nome = "2",
};
Pedido pedido = CreatePedido( string.Format( "Pedido {0}", 1 ), 2,cat );
repository.Add( pedido );
catRepo.Add( cat );
unitOfWork.Commit();
}
private static Pedido CreatePedido(string assunto, int numberofInteractions, Categoria cat)
{
Pedido pedido = new Pedido
{
Assunto = assunto,
Categoria = cat,
};
pedido.addCategoria( cat );
return pedido;
}
Спасибо, ребята