Esempio n. 1
0
        private static void UpdateWithMerging(Car disconnectedCar)
        {
            // #example: merging
            using (IObjectContainer container = OpenDatabase())
            {
                // first get the object from the database
                Car carInDb = GetCarById(container, disconnectedCar.ObjectId);

                // copy the value-objects (int, long, double, string etc)
                carInDb.Name = disconnectedCar.Name;

                // traverse into the references
                Pilot pilotInDB = carInDb.Pilot;
                Pilot disconnectedPilot = disconnectedCar.Pilot;

                // check if the object is still the same
                if (pilotInDB.ObjectId.Equals(disconnectedPilot.ObjectId))
                {
                    // if it is, copy the value-objects
                    pilotInDB.Name = disconnectedPilot.Name;
                    pilotInDB.Points = disconnectedPilot.Points;
                }
                else
                {
                    // otherwise replace the object
                    carInDb.Pilot = disconnectedPilot;
                }

                // finally store the changes
                container.Store(pilotInDB);
                container.Store(carInDb);
                // #end example
            }
        }
Esempio n. 2
0
 private static void UpdateCar(Car car)
 {
     car.Name = "Fast Car";
     car.Pilot.Points = 300;
 }