0
votes

Assume I have two classes related by one-two-many:

public class Customer
{
    public virtual Guid Id {get; set;}
    public virtual string Name {get; set;}
    public virtual IList<Order> Orders {get; set;}
}

public class Orders
{
    public virtual Guid Id {get; set;}
    public virtual string Name {get; set;}
    // public virtual Customer Customer {get; set;}`
}

And I don't want the documented Customer object in Orders class to be exist - but it means I can't use the References method to do the mapping References(x => x.Customer).

I used only the HasMany(x => x.Orders) method when mapping Customer object. When I created the tables and inserted data, the Foreign key column that was created by nhibernate (Customer_id )in the orders table is NULL.

Is it possible to do it without adding the Customer property to Orders object?

1
You need probably inverse: HasMany(x => x.Orders).Inverse()tykovec

1 Answers

0
votes

Not sure about the real reason:

...I don't want the documented Customer object in Orders...

The most likely is to hide it from the upper layers, to hide from the Business domain perspective.

In such case, we still should profit from the native behavior of ORM, which is driven by reference mapping. I.e. we should leave such reference on POCO level, keep it mapped, but let it be hidden for any other use. How? E.g. with protected access

//public  virtual Customer Customer {get; set;}
protected virtual Customer Customer {get; set;}

That could still be mapped, we still will profit from NH native features.. but upper layers won't be able to access Customer from Order...