public Hotel Get(int id)
        {
            _DEMOContext.ChangeTracker.LazyLoadingEnabled = false;

            var hotel = _DEMOContext.Hotel
                        .SingleOrDefault(b => b.HotelId == id);

            if (hotel == null)
            {
                return(null);
            }

            //_DEMOContext.Entry(hotel)
            //    .Collection(b => b.City)
            //    .Load();

            _DEMOContext.Entry(hotel)
            .Reference(b => b.City)
            .Load();


            //Many use : Collection
            return(hotel);
        }
Exemple #2
0
        public City Get(int id)
        {
            _DEMOContext.ChangeTracker.LazyLoadingEnabled = false;

            var city = _DEMOContext.City
                       .SingleOrDefault(b => b.CityId == id);

            if (city == null)
            {
                return(null);
            }

            //_DEMOContext.Entry(hotel)
            //    .Collection(b => b.City)
            //    .Load();

            _DEMOContext.Entry(city)
            .Collection(b => b.Hotel)
            .Load();


            //Many use : Collection
            return(city);
        }