﻿namespace Domain.OneToManyMapping
{
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;

  public class Order
  {
    public Order()
    {
      this.OrderLines = new List<OrderLine>();
    }

    public int Id { get; set; }
    public string Name { get; set; }
    public string Street { get; set; }
    public string ZipCode { get; set; }
    public string City { get; set; }

    public virtual ICollection<OrderLine> OrderLines { get; set; }

  }

  public class OrderLine
  {
    public int Id { get; set; }
    public string Description { get; set; }
    public double Amount { get; set; }

    /// Um Problem  
    ///   An error occurred while saving entities that do 
    ///   not expose foreign key properties for their 
    ///   relationships. The EntityEntries property will 
    ///   return null because a single entity cannot be 
    ///   identified as the source of the exception. 
    ///   Handling of exceptions while saving can be made easier 
    ///   by exposing foreign key properties in your entity types
    ///   zu vermeiden, das auftritt, wenn OrderLine Order eine
    /// Pflichteigenschaft ist. Verbessert den Umgang mit Validierungsfehlern.
    public int OrderId { get; set; }

    [Required()]
    public virtual Order Order { get; set; }
  }
}