private static bool OrderCompare(Order a, Order b)
 {
     if (Object.ReferenceEquals(a, b))
     {
         return true;
     }
     return a.Id == b.Id &&
         a.Reader == b.Reader &&
         a.Book == b.Book &&
         a.TimeGetBook == b.TimeGetBook &&
         a.LibrarianOpenOrder == b.LibrarianOpenOrder &&
         a.TimeReturnBook == b.TimeReturnBook &&
         a.LibrarianClosedOrder == b.LibrarianClosedOrder &&
         a.Closed == b.Closed;
 }
 public override void Save(Order item)
 {
     Order order = GetItem(item.Id);
     if (order == null)
     {
         context.Orders.InsertOnSubmit(item);
     }
     else
     {
         order.Book = item.Book;
         order.Reader = item.Reader;
         order.Department = item.Department;
         order.TimeGetBook = item.TimeGetBook;
         order.LibrarianOpenOrder = item.LibrarianOpenOrder;
         order.TimeReturnBook = item.TimeReturnBook;
         order.LibrarianClosedOrder = item.LibrarianClosedOrder;
         order.Closed = item.Closed;
     }
     context.SubmitChanges();
 }
        public bool OrderBook(Book book, Reader reader)
        {
            if (openOrders.Select(o => o.Book).Contains(book)) return false;
            if (!activeReaders.Contains(reader)) return false;

            Order order = new Order(reader, book);
            order.TimeGetBook = DateTime.Now;
            order.TimeReturnBook = DateTime.Now;
            order.LibrarianOpenOrder = workLibrarians.First(l => l.Department == book.Department);

            openOrders.Add(order);
            repository.OrderRepository.Save(order);

            return true;
        }
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Department = null;
		}
 public override void Remove(Order item)
 {
     Remove(item.Id);
 }
		private void detach_Orders1(Order entity)
		{
			this.SendPropertyChanging();
			entity.LibrarianClosedOrder = null;
		}
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Department = this;
		}
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Reader = null;
		}
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.LibrarianOpenOrder = this;
		}
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Reader = this;
		}
 partial void DeleteOrder(Order instance);
 partial void UpdateOrder(Order instance);
 partial void InsertOrder(Order instance);
 public OrderTest()
 {
     o1 = new Order(new Reader("Name1", "Address1"), new Book("Author1", "Title1", 2000, new LibraryDepartment("Абонемент", true)));
     o2 = new Order(o1.Reader, o1.Book) { Closed = true };
     o3 = new Order(o1.Id, o1.Reader, o1.Book);
 }