コード例 #1
0
        public void UpdateDealRecord(DealRecord deal)
        {
            MasterFI mFI = context.MasterFIs.Where(m => m.MasterFiId == deal.MasterFiId).FirstOrDefault();

            foreach (var prop in deal.GetType().GetProperties())
            {
                if (mFI.GetType().GetProperty(prop.Name) != null)
                {
                    var sourceValue = mFI.GetType().GetProperty(prop.Name).GetValue(deal, null);
                    prop.SetValue(mFI, sourceValue, null);
                }
            }
            context.SaveChanges();
        }
コード例 #2
0
        public void AddDealRecord(DealRecord deal)
        {
            MasterFI            mFI       = new MasterFI();
            IList <PropertyMap> propItems = GetPropertyMap(deal.GetType(), mFI.GetType());

            foreach (var prop in propItems)
            {
                var sourceValue = prop.DealProperty.GetValue(deal, null);
                prop.MasterProperty.SetValue(mFI, sourceValue, null);
            }

            context.MasterFIs.Add(mFI);
            try
            {
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
コード例 #3
0
        //public MasterFI GetDealRecord(int dorID)
        //{
        //    MasterFI record = context.MasterFIs.Where(m => m.DORid == dorID).FirstOrDefault();
        //    return record;
        //}

        public DealRecord GetDealRecord(int dorID)
        {
            DealRecord record = new DealRecord();
            MasterFI   mFI    = context.MasterFIs.Where(m => m.DORid == dorID).FirstOrDefault();

            foreach (var prop in record.GetType().GetProperties())
            {
                if (mFI.GetType().GetProperty(prop.Name) != null)
                {
                    var sourceValue = mFI.GetType().GetProperty(prop.Name).GetValue(mFI, null);
                    prop.SetValue(record, sourceValue, null);
                }
            }

            return(record);
        }