New Dictionary Mapping Question

4 views
Skip to first unread message

kimsk112

unread,
Sep 8, 2010, 4:30:38 PM9/8/10
to Fluent NHibernate
Firstly, I just want to thank anyone who contributed to the project. I
really appreciate your effort.

I just downloaded the build #692, and I am trying to update my code to
be compliant with new Dictionary Mapping.

Here are my classes:

public class Person
{
...
public virtual IDictionary<string, Identification> Ids {get;set;}
}

public class Identification
{
public virtual string Type { get; set; }
public virtual string Value { get; set; }
}


My current mapping is below:

public class PersonMap : SubclassMap<Person>
{
public PersonMap()
{
...
HasMany<Identification>(x => x.Ids)
.AsMap<string>(x => x.Type)
.Cascade.AllDeleteOrphan()
.NotFound.Ignore();
...
}
}

public class IdentificationMap : SubclassMap<Identification>
{
public IdentificationMap()
{
Table("IDENTIFICATION");
Map(x => x.Value)
.Not.Nullable();
Map(x => x.Type);
}
}


How should I map them with the new Dictionary Mapping?

Thanks,
Karlkim


James Gregory

unread,
Sep 8, 2010, 6:14:22 PM9/8/10
to fluent-n...@googlegroups.com
HasMany(x => x.Ids) should do the trick. Does it not?

> --
> You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
> To post to this group, send email to fluent-n...@googlegroups.com.
> To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
>

kimsk

unread,
Sep 9, 2010, 10:50:25 AM9/9/10
to fluent-n...@googlegroups.com
That should work, but my mapping requires the specific key column. I
think I was just not sure how the new syntax work.

Anyway, I found the issue by comparing the hbm files. It turns out
that I have to also specify OneToMany() into the mapping as well
otherwise it is trying to make it ManyToMany.

Old Mapping
=========


HasMany<Identification>(x => x.Ids)
.AsMap<string>(x => x.Type)

.Cascade.AllDeleteOrphan();

New Mapping
==========
HasMany(x => x.Ids)
.DictionaryKey<string>("Type")
.OneToMany()
.Cascade.AllDeleteOrphan();

Thanks!

--
Karlkim SK
Go Vandy!

Reply all
Reply to author
Forward
0 new messages