Esempio n. 1
0
        public void AddOperatorRules(ExelConvertionRule[] rules)
        {
            if (rules != null && rules.FirstOrDefault() != null)
                try
                {
                    using (var dc = exelconverterEntities2.New())
                    {
                        convertion_rules[] convRules =
                            rules
                            .Select(r => SetRuleToRow(null, r))
                            .ToArray();

                        foreach (var rule in convRules)
                            dc.convertion_rules.Add(rule);

                        dc.SaveChanges();

                        for (int i = 0; i < convRules.Length; i++)
                            rules[i].Id = convRules[i].id;
                    }
                }
                catch(DbEntityValidationException ex)
                {
                    StringBuilder sb = new StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                        foreach (var error in failure.ValidationErrors)
                        {
                            sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                            sb.AppendLine();
                        }
                    }

                    throw new DbEntityValidationException(
                        "Entity Validation Failed - errors follow:\n" +
                        sb.ToString(), ex
                    ); // Add the original exception as the innerException
                }
        }
Esempio n. 2
0
 public void RemoveOpertaorRule(ExelConvertionRule[] rules)
 {
     if (rules != null && rules.Length > 0)
         RemoveOpertaorRule(rules.Select(r => r.Id).ToArray());
 }