Datei: StressTests/StressTestClasses/SalesOrder.cs
Last Commit (9de6a8c)
| 1 | -- File didn't exist -- |
New Commit (bbf1d57)
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Linq; |
| 4 | using NDO; |
| 5 | using NDO.Mapping.Attributes; |
| 6 | |
| 7 | namespace StressTestClasses |
| 8 | { |
| 9 | ····/// <summary> |
| 10 | ····/// A sales order with three kinds of relations: |
| 11 | ····/// a directed n:1 relation to the customer (foreign key in the order table), |
| 12 | ····/// a bidirectional composite 1:n relation to the order lines (foreign key in the order line table) |
| 13 | ····/// and a directed n:m relation to tags (mapping table). |
| 14 | ····/// </summary> |
| 15 | ····[NDOPersistent] |
| 16 | ····public class SalesOrder |
| 17 | ····{ |
| 18 | ········string orderNumber; |
| 19 | ········DateTime orderDate; |
| 20 | ········string status; |
| 21 | ········decimal total; |
| 22 | |
| 23 | ········[NDORelation] |
| 24 | ········Customer customer; |
| 25 | |
| 26 | ········[NDORelation( RelationInfo.Composite )] |
| 27 | ········List<OrderLine> lines = new List<OrderLine>(); |
| 28 | |
| 29 | ········[NDORelation, MappingTable] |
| 30 | ········List<Tag> tags = new List<Tag>(); |
| 31 | |
| 32 | ········public SalesOrder() |
| 33 | ········{ |
| 34 | ········} |
| 35 | |
| 36 | ········public string OrderNumber |
| 37 | ········{ |
| 38 | ············get { return orderNumber; } |
| 39 | ············set { orderNumber = value; } |
| 40 | ········} |
| 41 | |
| 42 | ········public DateTime OrderDate |
| 43 | ········{ |
| 44 | ············get { return orderDate; } |
| 45 | ············set { orderDate = value; } |
| 46 | ········} |
| 47 | |
| 48 | ········public string Status |
| 49 | ········{ |
| 50 | ············get { return status; } |
| 51 | ············set { status = value; } |
| 52 | ········} |
| 53 | |
| 54 | ········public decimal Total |
| 55 | ········{ |
| 56 | ············get { return total; } |
| 57 | ············set { total = value; } |
| 58 | ········} |
| 59 | |
| 60 | ········public Customer Customer |
| 61 | ········{ |
| 62 | ············get { return customer; } |
| 63 | ············set { customer = value; } |
| 64 | ········} |
| 65 | |
| 66 | ········public IEnumerable<OrderLine> Lines => this.lines; |
| 67 | |
| 68 | ········public OrderLine NewLine( string product, int quantity, decimal price ) |
| 69 | ········{ |
| 70 | ············var line = new OrderLine() { Product = product, Quantity = quantity, Price = price }; |
| 71 | ············this.lines.Add( line ); |
| 72 | ············return line; |
| 73 | ········} |
| 74 | |
| 75 | ········public void RemoveLine( OrderLine line ) |
| 76 | ········{ |
| 77 | ············this.lines.Remove( line ); |
| 78 | ········} |
| 79 | |
| 80 | ········public IEnumerable<Tag> Tags => this.tags; |
| 81 | |
| 82 | ········public void AddTag( Tag tag ) |
| 83 | ········{ |
| 84 | ············this.tags.Add( tag ); |
| 85 | ········} |
| 86 | |
| 87 | ········public void RemoveTag( Tag tag ) |
| 88 | ········{ |
| 89 | ············this.tags.Remove( tag ); |
| 90 | ········} |
| 91 | |
| 92 | ········public decimal ComputeTotal() |
| 93 | ········{ |
| 94 | ············return this.lines.Sum( l => l.Quantity * l.Price ); |
| 95 | ········} |
| 96 | ····} |
| 97 | } |
| 98 |