Beispiel #1
0
        private static void InsertCategory()
        {
            //var lowes = new Category {
            //  Name = "Lowes"
            //};
            //var mon = new Category {
            //  Name = "Monrovia"
            //};

            using (var ctx = new SqrlContext())
            {
                //var root = ctx.Categories.FirstOrDefault(c => c.Name == "Root");
                var lowes = ctx.Categories.FirstOrDefault(c => c.Name == "Lowes");

                for (var i = 0; i < 1; i++)
                {
                    var link = new UrlLink();
                    link.Name = string.Format("L{0}", i.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0'));
                    link.Id = "20pN4";
                    link.LongUrl = string.Format("http://mobile.plantfinder.com/?PlantId={0}&FromTag=true", link.Name);
                    link.Parent = lowes;
                    ctx.UrlLinks.Add(link);
                    var valErrors = ctx.GetValidationErrors();
                    if (!valErrors.Any())
                    {
                        ctx.SaveChanges();
                    }
                }
                //ctx.Categories.Add(lowes);
                //ctx.Categories.Add(mon);
                //ctx.SaveChanges();
            }
        }
Beispiel #2
0
        private static void InsertLinkUrl()
        {
            using (var ctx = new SqrlContext())
            {
                var lowes = ctx.Categories.FirstOrDefault(c => c.Name == "Lowes");

                for (var i = 0; i < 10; i++)
                {
                    var link = new UrlLink();
                    link.Name = string.Format("L{0}", link.Id);
                    link.LongUrl = string.Format("http://mobile.plantfinder.com/?PlantId={0}&FromTag=true", link.Name);
                    link.Parent = lowes;

                    while (ctx.UrlLinks.Any(u => u.Id == link.Id))
                    {
                        link.Id = RandomGen.RandomString(SQRL.Domain.Properties.Settings.Default.RandomStringLength);
                    }

                    ctx.UrlLinks.Add(link);
                    ctx.SaveChanges();
                }
                //ctx.SaveChanges();
            }
        }
Beispiel #3
0
        private static void TestNameCategoryConstraint()
        {
            using (var ctx = new SqrlContext())
            {
                var lowes = ctx.Categories.FirstOrDefault(c => c.Name == "Lowes");
                var link = new UrlLink { Name = "LLLLL", Parent = lowes };

                ctx.UrlLinks.Add(link);
                //ctx.SaveChanges();
                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateException exc)
                {
                    if (exc.InnerException.InnerException.Message.Contains("UQ_Name_ParentId"))
                    {
                        Console.WriteLine("Tag name is not unique for this category. Please try a different tag name.");
                    }
                }
            }
        }