Пример #1
0
        /// <summary>
        /// M17_CYSNの新規追加
        /// </summary>
        /// <param name="m17cysn">M17_CYSN_Member</param>
        public void Insert(M17_CYSN_Member m17cysn)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                M17_CYSN m17 = new M17_CYSN();
                //m17.車輌KEY = m17cysn.車両ID;
                m17.年月 = m17cysn.年月;
                //m17.登録日時 = m17cysn.登録日時;
                //m17.更新日時 = m17cysn.更新日時;
                //m17.目標燃費 = m17cysn.目標燃費;
                try
                {
                    // newのエンティティに対してはAcceptChangesで新規追加となる
                    context.M17_CYSN.ApplyChanges(m17);
                    context.SaveChanges();
                }
                catch (UpdateException ex)
                {
                    // PKey違反等
                    Console.WriteLine(ex);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// M17_CYSNの物理削除
        /// </summary>
        /// <param name="m17cysn">M17_CYSN_Member</param>
        public void Delete(M17_CYSN_Member m17cysn)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M17_CYSN
                          where (x.車輌KEY == m17cysn.車両KEY && x.年月 == m17cysn.年月)
                          orderby x.車輌KEY, x.年月
                select x;
                var m17 = ret.FirstOrDefault();

                context.DeleteObject(m17);
                context.SaveChanges();
            }
        }
Пример #3
0
        /// <summary>
        /// M17_CYSNの更新
        /// </summary>
        /// <param name="m17cysn">M17_CYSN_Member</param>
        public void Update(M17_CYSN_Member m17cysn)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //更新行を特定
                var ret = from x in context.M17_CYSN
                          where (x.車輌KEY == m17cysn.車両KEY && x.年月 == m17cysn.年月)
                          orderby x.車輌KEY, x.年月
                select x;
                var m17 = ret.FirstOrDefault();
                //m17.車輌KEY = m17cysn.車両ID;
                m17.年月 = m17cysn.年月;
                //m17.登録日時 = m17cysn.登録日時;
                //m17.更新日時 = DateTime.Now;
                //m17.目標燃費 = m17cysn.目標燃費;

                m17.AcceptChanges();
                context.SaveChanges();
            }
        }