Ejemplo n.º 1
0
        public static void Task4()
        {
            Table <NewEquipment> equips = db.GetTable <NewEquipment>();
            var query = from eq in equips select
                        new  {
                equipmentID = eq.IntEquipmentID,
                garageRoom  = eq.IntGarageRoom,
            };

            Console.WriteLine("EquipmentID \t GarageRoom");
            foreach (var item in query)
            {
                Console.WriteLine(item.equipmentID + "\t\t" + item.garageRoom);
            }
        }
Ejemplo n.º 2
0
        public static void Task2AndTask3()
        {
            //2.Используя класс DataContext произвести
            //    выборку данных из таблицы TableEquipmentHistory
            //    и newEquipment используя при этом join выгрузить
            //    следующие данные: intGarageRoom, strSerialNo,
            //intTypeHistory, dStartDate, dEndDate, intDaysCount, intStatys

            Table <TableEquipmentHistory> tabEqHis = db.GetTable <TableEquipmentHistory>();
            Table <newEquipment>          newEq    = db.GetTable <newEquipment>();

            var jtabs = from a in tabEqHis
                        join b in newEq on a.intEquipmentID equals b.intEquipmentID
                        select new
            {
                a.intEquipmentID,
                b.intGarageRoom,
                b.strSerialNo,
                a.intTypeHistory,
                a.dStartDate,
                a.dEndDate,
                a.intDaysCount,
                a.intStatys
            };

            foreach (var item in jtabs)
            {
                Console.WriteLine("EquipmentID - " + item.intEquipmentID);
                Console.WriteLine("GarageRoom - " + item.intGarageRoom);
                Console.WriteLine("SerialNo - " + item.strSerialNo);
                Console.WriteLine("TypeHistory - " + item.intTypeHistory);
                Console.WriteLine("StartDate - " + item.dStartDate);
                Console.WriteLine("EndDate - " + item.dEndDate);
                Console.WriteLine("DaysCount - " + item.intDaysCount);
                Console.WriteLine("Statys - " + item.intStatys);
                Console.WriteLine("****************************************");
                Console.WriteLine();
            }

            //3.Из результатов пункта 2, создать таблицу в БД,
            //и результаты первой выборки загрузить во вновь созданную таблицу

            db.ExecuteCommand(" IF not EXISTS(SELECT * FROM sys.tables WHERE name = 'NewTable') begin create table NewTable (NewTableId int primary key identity(1,1)," +
                              "EquipmentID int, GarageRoom nvarchar(100),SerialNo nvarchar(100)," +
                              "TypeHistory int, StartDate date, EndDate date, DaysCount int, Statys int) end");

            List <NewTable> newTab = new List <NewTable>();

            foreach (var item in jtabs)
            {
                NewTable tab = new NewTable();
                tab.DaysCount   = item.intDaysCount;
                tab.EndDate     = item.dEndDate;
                tab.EquipmentID = item.intEquipmentID;
                tab.GarageRoom  = item.intGarageRoom;
                tab.SerialNo    = item.strSerialNo;
                tab.StartDate   = item.dStartDate;
                tab.Statys      = item.intStatys;
                tab.TypeHistory = item.intTypeHistory;
                newTab.Add(tab);
            }

            Table <NewTable> nt = db.GetTable <NewTable>();

            try
            {
                nt.InsertAllOnSubmit(newTab);
                db.SubmitChanges();
                Console.WriteLine("Данные сохранены в таблицу");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }