Свободная проблема отображения словаря NHibernate - PullRequest
2 голосов
/ 04 ноября 2010


У меня есть следующие лица

public class Entity1
 {
  public virtual Guid Id { get; set; }
  public virtual IDictionary<Guid, Entity2> Entities2 { get; set; }
 }

 public class Entity2
 {
  public virtual Guid Id { get; set; }
  public virtual IDictionary<Guid, Entity1> Entities1 { get; set; }
 }

таблица БД

CREATE TABLE [dbo].[EntityLinks](
  [Entity1Id] [uniqueidentifier] NOT NULL,
  [Entity2Id] [uniqueidentifier] NOT NULL,
  [LinkItemId] [uniqueidentifier] NOT NULL
 )

и следующие сопоставления:

для Entity1

mapping.HasManyToMany<Entity2>(rc => rc.Entities2)
  .Table("EntityLinks")
  .ParentKeyColumn("Entity1Id")
  .ChildKeyColumn("Entity2Id")
  .AsMap<Guid>("LinkItemId")

для Entity2

mapping.HasManyToMany<Entity1>(rc => rc.Entities1)
  .Table("EntityLinks")
  .ParentKeyColumn("Entity2Id")
  .ChildKeyColumn("Entity1Id")
  .AsMap<Guid>("LinkItemId")

добавление данных работает нормально, и я могу получить и увидеть заполненный Entity1.Entities2, но Entity2.Entities1 не заполнен.

Есть предложения, почему это может быть?

Заранее спасибо.

1 Ответ

0 голосов
/ 04 ноября 2010

Возможно, я не прав, но вы можете попробовать:

mapping.HasManyToMany<Entity2>(rc => rc.Entities2)
  .Table("EntityLinks")
  .ParentKeyColumn("Entity1Id")
  .ChildKeyColumn("Entity2Id")
  .AsMap<Guid>("LinkItemId")
  .Inverse()

и

mapping.HasManyToMany<Entity1>(rc => rc.Entities1)
  .Table("EntityLinks")
  .ParentKeyColumn("Entity2Id")
  .ChildKeyColumn("Entity1Id")
  .AsMap<Guid>("LinkItemId")
  .Cascade.All();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...