Simple Mapping Problem

7 views
Skip to first unread message

aeden....@gmail.com

unread,
Nov 20, 2009, 2:04:09 AM11/20/09
to nhusers
I have what appears to be a common and simple model. I have a
Subscription entity which contains the value object PaymentMethod.
The PaymentMethods are CreditCard or ECheck. I map the Subscription
class as an entity and I would like to map the PaymentMethod has a
component, but component mappings don't support polymorphism. Or do
they? How do other people handle this? Or is there something wrong
with the modeling?

Cheers,
Aeden

Jason Meckley

unread,
Nov 20, 2009, 8:16:54 AM11/20/09
to nhusers
components do not allow for polymorphism. you need to implement your
own IUserType to manage PaymentType. You're other option is to map
PaymentType to an entity (requires db schema change.)

On Nov 20, 2:04 am, "aeden.jame...@gmail.com"

aeden....@gmail.com

unread,
Nov 20, 2009, 4:13:29 PM11/20/09
to nhusers
Hmmm..... are there any examples out there for this scenario?

If not, can you sketch how it might be achieved because there are some
details that I'm fuzzy on.

If one uses IUserType I won't be able to query
on the properties and so suppose I implement ICompositeUserType
for the ValueObject PaymentMethod to be used like this

class Subscription {
public PaymentMethod PaymentMethod { get; set; }
}

class PaymentMethod

class CreditCard : PaymentMethod

class ECheck : PaymentMethod


so a given subcription I would like the correct type of
instance to be returned. (e.g.CreditCard or an ECheck)
and when I query.

One of the details I'm confused about is based on my understanding
would I have to, in the property mapping, list all the columns
involved in mapping
each class e.g.

<property name="" class="PaymentMethodCustomType>
<column name="CardNumber"/>
<column name="Expiration"/>
<column name="CSC"/>
.....
<column name="CheckAccountNumber"/>
<column name="RoutingNumber"/>
.....

</property>

and in the GetProperties Method I would list all of the Properties in
every class?
Is that right?

Lastly, this seems like a straight forward use case for mapping, but
not obvious
as to how to map the model. Why? Perhaps this should be a feature or
maybe
the difficulty is telling me my modeling is off. If so, does anyone
have any insights?

Cheers,
Aeden
> > Aeden- Hide quoted text -
>
> - Show quoted text -

Jason Meckley

unread,
Nov 20, 2009, 5:11:16 PM11/20/09
to nhusers
I think you are on the right track. yes, you need to define the
columns in the property mapping, and these properties will also play a
role in the implementation.
I would first start with mapping via IUserType. once this is working
and you understand how it works, you can implement ICompositeUserType
which should allow you to query properties of the payment type.

On Nov 20, 4:13 pm, "aeden.jame...@gmail.com"

aeden....@gmail.com

unread,
Nov 21, 2009, 1:25:00 PM11/21/09
to nhusers
Thanks Jason. I really appreciate your guidance. I don't now if you
would
consider yourself an expert, but none-the-less, any thoughts on my
last question?

>Lastly, this seems like a straight forward use case for mapping, but
>not obvious as to how to map the model. Why? Perhaps it (Polymorphic Components)
>should be a feature or maybe the difficulty is telling me my modeling is off. If so, does anyone
>have any insights?


Cheers,
Aeden

> > > - Show quoted text -- Hide quoted text -

Jason Meckley

unread,
Nov 21, 2009, 3:34:08 PM11/21/09
to nhusers
no, not an expert :)
I remember seeing an example of payments in the hierarchy mapping
documentation. I think they where using entities though, not value
objects.

On Nov 21, 1:25 pm, "aeden.jame...@gmail.com"
Reply all
Reply to author
Forward
0 new messages