-
-
Save stanb/22389e2b65c1293939a0 to your computer and use it in GitHub Desktop.
Code for uniderectional association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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