Exemple #1
0
        public IList <Vehicle> GetAll()
        {
            VehicleDBEntities db = new VehicleDBEntities();

            try
            {
                var vehQuery = from veh in db.VehicleModelYear
                               select veh;

                var ret = vehQuery.Select(vh => new Vehicle()
                {
                    Id = vh.id, Manufacturer = vh.make, Model = vh.model, Year = vh.year
                }).ToList();
                //Lets only return 1000 records
                return(ret);
            }
            finally
            {
                db.Dispose();
            }
        }
Exemple #2
0
        public override IEnumerable <Vehicle> Get(int page, int size)
        {
            int skip = page == 1 ? 0 : (page - 1) * size + 1;

            VehicleDBEntities db = new VehicleDBEntities();

            try
            {
                var vehQuery = db.VehicleModelYear.OrderBy(vmy => vmy.id).Skip(skip).Take(size);

                var ret = vehQuery.Select(vh => new Vehicle()
                {
                    Id = vh.id, Manufacturer = vh.make, Model = vh.model, Year = vh.year
                }).ToList();
                //Lets only return 1000 records
                return(ret);
            }
            finally
            {
                db.Dispose();
            }
        }
Exemple #3
0
        public override Vehicle Get(int id)
        {
            VehicleDBEntities db = new VehicleDBEntities();

            try
            {
                var vehQuery = from veh in db.VehicleModelYear
                               where veh.id == id
                               select veh;

                var vehicle = vehQuery.Select(vh => new Vehicle()
                {
                    Id = vh.id, Manufacturer = vh.make, Model = vh.model, Year = vh.year
                }).ToList().FirstOrDefault();

                return(vehicle);
            }
            finally
            {
                db.Dispose();
            }
        }