public override int Run(string[] remainingArguments)
        {
            using (var db = new WidgetContext())
            {
                var widget = new Widget
                {
                    Value = "foo",
                    Gadgets = new List<Gadget>
                    {
                        new Gadget
                        {
                            Value = 30
                        }
                    }
                };

                db.Widgets.Add(widget);

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var formattedException = ex.FormatToString();
                    Console.WriteLine(formattedException);
                }
            }

            return 0;
        }
Пример #2
0
        public override int Run(string[] remainingArguments)
        {
            using (var db = new WidgetContext())
            {
                var widget = new Widget
                {
                    Value   = "foo",
                    Gadgets = new List <Gadget>
                    {
                        new Gadget
                        {
                            Value = 30
                        }
                    }
                };

                db.Widgets.Add(widget);

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    var formattedException = ex.FormatToString();
                    Console.WriteLine(formattedException);
                }
            }

            return(0);
        }