Mapping a property to a field from another table in NHibernate

consider the following class:

class Order {
    int OrderId {get; set;}
    int CustomerId {get; set;}
    string CustomerName {get; set;}
    //other fields go here
}

which is displayed in the order table. Can I map a CustomerName property to a Customers table with a foreign key relationship?

0
source share
2 answers

Yes, you can use the join display element for this. Another option is to match the view instead of the table. But, if possible, you should use an object-oriented approach and map the many-to-many relationship between the order and the customer.

0
source

<join/> . , , .

. , , order.Customer.Name.

, :

1) Customer Order

public virtual Customer Customer { get; set; }

2) ( CustomerId - FK)

<many-to-one name="Customer" column="CustomerId"/>

3) CustomerName, :

public virtual string CustomerName { get { return Customer.Name; } }
0

Source: https://habr.com/ru/post/1760334/


All Articles