Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Code for uniderectional association
public class Order
{
public virtual Guid Id { get; set; }
public virtual int Version { get; set; }
public virtual DateTime OrderTime { get; set; }
public virtual ICollection<OrderLine> OrderLines { get; set; }
}
public class OrderLine
{
public virtual Guid Id { get; set; }
public virtual string ProductName { get; set; }
public virtual decimal Price { get; set; }
public virtual int Quantity { get; set; }
}
...
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
var order = session.Get<Order>(id);
order.OrderLines.Add(new OrderLine
{
ProductName = "Product 1",
Price = 9.99M,
Quantity = 15
});
tx.Commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment