开发者

Fluent NHibernate Dictionary mapping problem

I have following entities

public class Entity1
 {
  public virtual Guid Id { get; se开发者_Python百科t; }
  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; }
 }

DB table

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

and following mappings:

for Entity1

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

for Entity2

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

adding data works fine and I can get and see Entity1.Entities2 populated but Entity2.Entities1 is not populated.

Any suggestions why this might be?

Thank you in advance.


I'm probably wrong but you can try:

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

and

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜