comparison UnitTests/Linq/Model/Northwind.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections.Generic;
3 using System.Data.Linq;
4
5 using BLToolkit.DataAccess;
6 using BLToolkit.Mapping;
7
8 namespace Data.Linq.Model
9 {
10 public class Northwind
11 {
12 public abstract class EntityBase<T>
13 {
14 protected abstract T Key { get; }
15
16 public override bool Equals(object obj)
17 {
18 return GetType() == obj.GetType() && Key.Equals(((EntityBase<T>)obj).Key);
19 }
20
21 public override int GetHashCode()
22 {
23 return Key.GetHashCode();
24 }
25 }
26
27 [TableName("Categories")]
28 public class Category
29 {
30 [PrimaryKey, NonUpdatable] public int CategoryID;
31 [NotNull] public string CategoryName;
32 public string Description;
33 public Binary Picture;
34
35 [Association(ThisKey="CategoryID", OtherKey="CategoryID")]
36 public List<Product> Products;
37 }
38
39 [TableName("CustomerCustomerDemo")]
40 public class CustomerCustomerDemo
41 {
42 [PrimaryKey, NotNull] public string CustomerID;
43 [PrimaryKey, NotNull] public string CustomerTypeID;
44
45 [Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID")]
46 public CustomerDemographic CustomerDemographics;
47
48 [Association(ThisKey="CustomerID", OtherKey="CustomerID")]
49 public Customer Customers;
50 }
51
52 [TableName("CustomerDemographics")]
53 public class CustomerDemographic
54 {
55 [PrimaryKey, NotNull] public string CustomerTypeID;
56 public string CustomerDesc;
57
58 [Association(ThisKey="CustomerTypeID", OtherKey="CustomerTypeID")]
59 public List<CustomerCustomerDemo> CustomerCustomerDemos;
60 }
61
62 [TableName("Customers")]
63 public class Customer : EntityBase<string>
64 {
65 [PrimaryKey] public string CustomerID;
66 [NotNull] public string CompanyName;
67 public string ContactName;
68 public string ContactTitle;
69 public string Address;
70 public string City;
71 public string Region;
72 public string PostalCode;
73 public string Country;
74 public string Phone;
75 public string Fax;
76
77 [Association(ThisKey="CustomerID", OtherKey="CustomerID")]
78 public List<CustomerCustomerDemo> CustomerCustomerDemos;
79
80 [Association(ThisKey="CustomerID", OtherKey="CustomerID")]
81 public List<Order> Orders;
82
83 protected override string Key
84 {
85 get { return CustomerID; }
86 }
87 }
88
89 [TableName("Employees")]
90 public class Employee : EntityBase<int>
91 {
92 [PrimaryKey, NonUpdatable] public int EmployeeID;
93 [NotNull] public string LastName;
94 [NotNull] public string FirstName;
95 public string Title;
96 public string TitleOfCourtesy;
97 public DateTime? BirthDate;
98 public DateTime? HireDate;
99 public string Address;
100 public string City;
101 public string Region;
102 public string PostalCode;
103 public string Country;
104 public string HomePhone;
105 public string Extension;
106 public Binary Photo;
107 public string Notes;
108 public int? ReportsTo;
109 public string PhotoPath;
110
111 [Association(ThisKey="EmployeeID", OtherKey="ReportsTo")] public List<Employee> Employees;
112 [Association(ThisKey="EmployeeID", OtherKey="EmployeeID")] public List<EmployeeTerritory> EmployeeTerritories;
113 [Association(ThisKey="EmployeeID", OtherKey="EmployeeID")] public List<Order> Orders;
114 [Association(ThisKey="ReportsTo", OtherKey="EmployeeID")] public Employee ReportsToEmployee;
115
116 //[MapIgnore]
117 protected override int Key
118 {
119 get { return EmployeeID; }
120 }
121 }
122
123 [TableName("EmployeeTerritories")]
124 public class EmployeeTerritory
125 {
126 [PrimaryKey] public int EmployeeID;
127 [PrimaryKey, NotNull] public string TerritoryID;
128
129 [Association(ThisKey="EmployeeID", OtherKey="EmployeeID")] public Employee Employee;
130 [Association(ThisKey="TerritoryID", OtherKey="TerritoryID")] public Territory Territory;
131 }
132
133 [TableName("Order Details")]
134 public class OrderDetail
135 {
136 [PrimaryKey] public int OrderID;
137 [PrimaryKey] public int ProductID;
138 public decimal UnitPrice;
139 public short Quantity;
140 public float Discount;
141
142 [Association(ThisKey="OrderID", OtherKey="OrderID")] public Order Order;
143 [Association(ThisKey="ProductID", OtherKey="ProductID")] public Product Product;
144 }
145
146 [TableName("Orders")]
147 public class Order : EntityBase<int>
148 {
149 [PrimaryKey, NonUpdatable] public int OrderID;
150 public string CustomerID;
151 public int? EmployeeID;
152 public DateTime? OrderDate;
153 public DateTime? RequiredDate;
154 public DateTime? ShippedDate;
155 public int? ShipVia;
156 public decimal Freight;
157 public string ShipName;
158 public string ShipAddress;
159 public string ShipCity;
160 public string ShipRegion;
161 public string ShipPostalCode;
162 public string ShipCountry;
163
164 [Association(ThisKey="OrderID", OtherKey="OrderID")] public List<OrderDetail> OrderDetails;
165 [Association(ThisKey="CustomerID", OtherKey="CustomerID", CanBeNull=false)] public Customer Customer;
166 [Association(ThisKey="EmployeeID", OtherKey="EmployeeID")] public Employee Employee;
167 [Association(ThisKey="ShipVia", OtherKey="ShipperID")] public Shipper Shipper;
168
169 protected override int Key
170 {
171 get { return OrderID; }
172 }
173 }
174
175 [TableName("Products")]
176 [InheritanceMapping(Code=true, Type=typeof(DiscontinuedProduct))]
177 [InheritanceMapping(Code=false, Type=typeof(ActiveProduct))]
178 public abstract class Product
179 {
180 [PrimaryKey, NonUpdatable] public int ProductID;
181 [NotNull] public string ProductName;
182 public int? SupplierID;
183 public int? CategoryID;
184 public string QuantityPerUnit;
185 public decimal? UnitPrice;
186 public short? UnitsInStock;
187 public short? UnitsOnOrder;
188 public short? ReorderLevel;
189 [MapField(IsInheritanceDiscriminator=true)] public bool Discontinued;
190
191 [Association(ThisKey="ProductID", OtherKey="ProductID")] public List<OrderDetail> OrderDetails;
192 [Association(ThisKey="CategoryID", OtherKey="CategoryID")] public Category Category;
193 [Association(ThisKey="SupplierID", OtherKey="SupplierID")] public Supplier Supplier;
194 }
195
196 public class ActiveProduct : Product {}
197 public class DiscontinuedProduct : Product {}
198
199 [TableName("Region")]
200 public class Region
201 {
202 [PrimaryKey] public int RegionID;
203 [NotNull] public string RegionDescription;
204
205 [Association(ThisKey="RegionID", OtherKey="RegionID")]
206 public List<Territory> Territories;
207 }
208
209 [TableName("Shippers")]
210 public class Shipper
211 {
212 [PrimaryKey, NonUpdatable] public int ShipperID;
213 [NotNull] public string CompanyName;
214 public string Phone;
215
216 [Association(ThisKey="ShipperID", OtherKey="ShipVia")]
217 public List<Order> Orders;
218 }
219
220 [TableName("Suppliers")]
221 public class Supplier
222 {
223 [PrimaryKey, NonUpdatable] public int SupplierID;
224 [NotNull] public string CompanyName;
225 public string ContactName;
226 public string ContactTitle;
227 public string Address;
228 public string City;
229 public string Region;
230 public string PostalCode;
231 public string Country;
232 public string Phone;
233 public string Fax;
234 public string HomePage;
235
236 [Association(ThisKey="SupplierID", OtherKey="SupplierID")]
237 public List<Product> Products;
238 }
239
240 [TableName("Territories")]
241 public class Territory
242 {
243 [PrimaryKey, NotNull] public string TerritoryID;
244 [NotNull] public string TerritoryDescription;
245 public int RegionID;
246
247 [Association(ThisKey="TerritoryID", OtherKey="TerritoryID")]
248 public List<EmployeeTerritory> EmployeeTerritories;
249
250 [Association(ThisKey="RegionID", OtherKey="RegionID")]
251 public Region Region;
252 }
253 }
254 }