Hello, everyone
I'm learning NHibernate and tried to test model with SQLite in memory.
However, I found problem with many-to-one relation.
For instance, Customer can have many orders and order has one customer
reference.
In my test I create customer and attach order, when loading customer
back I can get order from customer. On the other hand, I can't get the
customer reference from that order.
this is my test
<code>
[Test]
public void CreateSuccess()
{
sessionFactory =
NHConfigurator.SessionFactory;
var session = sessionFactory.OpenSession();
Customer customer = new Customer()
{
Name = "ABC",
Address = new Address() { City = "Rachewi", State =
"Bangkok", StreetAddress = "123", Zip = "543" },
Orders = new List<Order>()
{
new Order(){ Date = DateTime.Now,OrderItems =
new List<Product>(){ new Product(){ Name
="product1"}}}
}
};
int id = (int) session.Save(customer);
Assert.AreEqual(1, id);
var c = session.Load<Customer>(id);
var order = c.Orders[0];
Assert.IsNotNull(order);
Assert.IsNotNull(order.Customer,"order.Customer is not
null");//can't reference to this customer object
session.Close();
}
</code>
it would be appreciated if you could you help me to solve this problem
since I tried many ways that I can and it took me a day and still got
this problem.
I've put source code on internet. You can download it here.
[download source code][1]
[1]: http://www.codesanook.com/shared/NHibernateSimpleDemo.rar
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.