예제 #1
0
        internal static Context.DataModel.Pizza Map(Library.DataClasses.Pizza pizza) //does not link foreign keys
        {
            if (pizza == null)
            {
                return(null);
            }
            DataModel.Pizza p = new DataModel.Pizza();

            p.SizeId  = pizza.Size.ID;
            p.CrustId = pizza.Crust.ID;
            if (pizza.Preset.ID != null)
            {
                p.PresetId = pizza.Preset.ID;
            }
            p.Amount = pizza.Amount;
            p.Price  = pizza.Price;

            foreach (var t in pizza.Toppings)
            {
                PizzaTopping1 nt = new PizzaTopping1();
                p.PizzaTopping1.Add(nt);
                nt.ToppingId = t.ID;
            }

            return(p);
        }
예제 #2
0
        public static Library.DataClasses.Pizza Map(Context.DataModel.Pizza pizza)
        {
            if (pizza == null)
            {
                return(null);
            }
            Library.DataClasses.Pizza p = new Library.DataClasses.Pizza();
            Database.GetContext().Entry(pizza).Reference("Size").Load();
            Database.GetContext().Entry(pizza).Reference("Crust").Load();
            Database.GetContext().Entry(pizza).Reference("Preset").Load();
            Database.GetContext().Entry(pizza).Collection("PizzaTopping1").Load();

            p.Size  = (pizza.SizeId, pizza.Size.Name);
            p.Crust = (pizza.CrustId, pizza.Crust.Name);
            if (pizza.PresetId != null)
            {
                p.Preset = (pizza.PresetId, pizza.Preset.Name);
            }
            p.Toppings = pizza.PizzaTopping1.Select(x => { Database.GetContext().Entry(x).Reference("Topping").Load(); return(x.ToppingId, x.Topping.Name); });
            p.Amount   = pizza.Amount;
            p.Price    = pizza.Price;

            return(p);
        }