HasOne not working

Emiliano's Avatar

Emiliano

02 Mar, 2010 12:02 PM via web

I'm having problems with a HasMany relationship, the things is I have a Customer who has a credit card and a Wishlist and also Orders, if I do

Customer.Orders : works ok
Customer.Wishlist: works ok
Customer.CreditCard: it is null, and there is data in the database

This is the mapping class

`public partial class CustomerMap:ClassMap

{
    public CustomerMap()
    {
        Id(x => x.Id).Column("CustID");

        Map(x => x.FirstName); 

        Map(x => x.MiddleInitial); 

        Map(x => x.LastName); 


        HasOne(x => x.Wishlist)
            .LazyLoad()
            .ForeignKey("CustID")
            .Cascade.All();

        HasOne(x => x.CreditCard)
            .ForeignKey("CustID")
            .LazyLoad()
            .Cascade.All();


        HasMany(x => x.Orders)
            .LazyLoad()
            .KeyColumn("CustID");

    }`

And this is the entity

`public partial class Customer

{
    public virtual CustomerCreditCard CreditCard { get; set; }
    public virtual IList<Order> Orders { get; set; }
    public virtual Wishlist Wishlist { get; set; }
}`

What i'm doing wrong? Is there any way to show debug info? or get some help to find the problem?

Thanks a lot!

  1. Support Staff 2 Posted by Hudson Akridge on 02 Mar, 2010 05:05 PM

    Hudson Akridge's Avatar

    You might want to change those to References() instead of HasOne(). This is often times not the mapping you're looking for.
    ref: http://jagregory.com/writings/i-think-you-mean-a-many-to-one-sir/

  2. 3 Posted by Emiliano on 03 Mar, 2010 12:03 AM

    Emiliano's Avatar

    Thanks a lot, I changed it, and it's working ;)

  3. James Gregory closed this discussion on 03 Mar, 2010 09:52 AM.

Comments are currently closed for this discussion. You can start a new one.