Mapping IList<Guid>. Is it possible?

391 views
Skip to first unread message

mynkow

unread,
May 4, 2012, 10:54:54 AM5/4/12
to fluent-n...@googlegroups.com
Hi

I have two tables: Orders and Products. The order object has a list<Guid> of products. How can I map this? At the moment I get: Association references unmapped class: System.Guid

10x

Tim Scott

unread,
May 4, 2012, 11:41:51 AM5/4/12
to fluent-n...@googlegroups.com

You will have to change NullSafeGet and NullSafeSet to convert between Guid and string.

Also, since this post predates FNH, I don't cover that in my answer.  Use something like .CustomType<DelimitedGuidList>() in your  FNH mapping of that property.

Tim
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/N7dARRmza00J.
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.

mynkow

unread,
May 7, 2012, 2:29:34 AM5/7/12
to fluent-n...@googlegroups.com
10x

mynkow

unread,
May 10, 2012, 2:33:14 PM5/10/12
to fluent-n...@googlegroups.com
Actually this will not work. I am not able to set custom type for ont-to-many or many-to-many.

May be I should say that the list of Guids is a list of PKs of product. Normally the mapping which is working is

HasMany<Product>(x=>x.Products)

Tim Scott

unread,
May 10, 2012, 7:01:26 PM5/10/12
to fluent-n...@googlegroups.com
That's right, CustomType is not for creating entity associations.  The type that I suggested is for mapping a list of things that is stored in a single database column.  It would work fine for IList<Guid>.  But if what you want is a one-to-many association, HasMany is the correct way to map that.
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/V2mXUTLIoawJ.

mynkow

unread,
May 13, 2012, 6:24:08 AM5/13/12
to fluent-n...@googlegroups.com
But I do not want the order to hold an objects of products. It does not make sense. A simple pointer of type guid is enough.

So, there is no way to do this with nhibernate?


On Friday, May 11, 2012 2:01:26 AM UTC+3, Tim Scott wrote:
That's right, CustomType is not for creating entity associations.  The type that I suggested is for mapping a list of things that is stored in a single database column.  It would work fine for IList<Guid>.  But if what you want is a one-to-many association, HasMany is the correct way to map that.

On Thursday, May 10, 2012 at 1:33 PM, mynkow wrote:

Actually this will not work. I am not able to set custom type for ont-to-many or many-to-many.

May be I should say that the list of Guids is a list of PKs of product. Normally the mapping which is working is

HasMany<Product>(x=>x.Products)

--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/V2mXUTLIoawJ.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibernate+unsubscribe@googlegroups.com.

Tim Scott

unread,
May 13, 2012, 7:14:09 PM5/13/12
to fluent-n...@googlegroups.com
I would be inclined to model Order-Product relation as a many-to-many association (HasManyToMany). This is implemented in the the DB as a table of ProductId and OrderId.  You'd want to make sure the association is lazy, which it would be by default.

If I decided to keep just the IDs I would probably use the DelimitedList user type that I wrote about before.  That's as good a way as I know to model a persisted list of value types.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/fKTilMfKW9IJ.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages