예제 #1
0
        public void NonIntuitive_ButSucceeds()
        {
            var engine = new Engine {
                Cylinders = 6, Horsepower = 200
            };
            var tires = new TirePackage {
                Size = 16, Weight = 40
            };
            var car = new PurchasedCar {
                CustomerName = "Me"
            };

            var context = GetEntityContext();

            // BAD: SetLink is not type safe and has poor readability
            // Note: Order is important AddToEngines and AddToPurcasedCars must come first.
            // Note: SetLink must come after calling AddTo*() on the context
            context.AddToEngines(engine);
            context.AddToTirePackages(tires);
            context.AddToPurchasedCars(car);
            context.SetLink(car, "Engine", engine);
            context.SetLink(car, "Tires", tires);

            context.SaveChanges(SaveChangesOptions.Batch);
        }
예제 #2
0
        public static TirePackage CreateTirePackage(int ID, int size, int weight)
        {
            TirePackage tirePackage = new TirePackage();

            tirePackage.Id     = ID;
            tirePackage.Size   = size;
            tirePackage.Weight = weight;
            return(tirePackage);
        }
예제 #3
0
        public void GoodInterface_ThrowsException()
        {
            var engine = new Engine {
                Cylinders = 6, Horsepower = 200
            };
            var tires = new TirePackage {
                Size = 16, Weight = 40
            };
            var car = new PurchasedCar {
                CustomerName = "Me", Engine = engine, Tires = tires
            };

            var context = GetEntityContext();

            context.AddToPurchasedCars(car);

            // BAD: Throws "Resource not found for the segment 'PurchasedCar'" error
            context.SaveChanges();
        }
예제 #4
0
 public static TirePackage CreateTirePackage(int ID, int size, int weight)
 {
     TirePackage tirePackage = new TirePackage();
     tirePackage.Id = ID;
     tirePackage.Size = size;
     tirePackage.Weight = weight;
     return tirePackage;
 }
예제 #5
0
 public void AddToTirePackages(TirePackage tirePackage)
 {
     base.AddObject("TirePackages", tirePackage);
 }
예제 #6
0
 public void AddToTirePackages(TirePackage tirePackage)
 {
     base.AddObject("TirePackages", tirePackage);
 }