Beispiel #1
0
        private static void InsertFromFile()
        {
            Console.WriteLine("Inserting form file");
            List <GeoJson> items = new List <GeoJson>();

            using (StreamReader r = new StreamReader("C:\\pl_malopolskie-addresses-state.geojson"))
            {
                string json;
                while ((json = r.ReadLine()) != null)
                {
                    items.Add(JsonConvert.DeserializeObject <GeoJson>(json));
                }
            }

            var factory    = new ConsoleAppFactory();
            var context    = factory.CreateDbContext();
            var postalList = new List <PostalCode>();
            var streets    = new List <Street>();

            foreach (var item in items)
            {
                var postalCode = new PostalCode();
                var street     = new Street();
                if (postalList.All(x => x.Code != item.properties.postcode))
                {
                    postalCode = new PostalCode {
                        Code = item.properties.postcode
                    };
                    postalList.Add(postalCode);
                }
                else
                {
                    postalCode = postalList.First(x => x.Code == item.properties.postcode);
                }

                if (streets.All(x => x.Name != item.properties.street))
                {
                    street = new Street {
                        Name = item.properties.street, PostalCodes = new List <PostalCode>()
                    };
                    streets.Add(street);
                }
                else
                {
                    street = streets.First(x => x.Name == item.properties.street);
                }

                street.PostalCodes.Add(postalCode);
            }

            context.PostalCodes.AddRange(postalList);
            context.Streets.AddRange(streets);
            var result = context.SaveChanges();

            Console.WriteLine("OK " + result);
        }
Beispiel #2
0
        private static void StoredProcedure(string ZipCode)
        {
            var factory = new ConsoleAppFactory();
            var context = factory.CreateDbContext();
            var result  =
                context.SPResult.FromSqlInterpolated($"GetStreets {ZipCode}");

            foreach (var r in result)
            {
                Console.WriteLine($"{r.Name}");
            }
        }
Beispiel #3
0
        private static void StoredProcedureInsert()
        {
            var insert = new InsertProcedureTemplate
            {
                InsertName   = "Test",
                InsertNumber = 787
            };
            var factory = new ConsoleAppFactory();
            var context = factory.CreateDbContext();

            context.Database.ExecuteSqlInterpolated($"InsertProcedure {insert.InsertName}, {insert.InsertNumber}");
        }
Beispiel #4
0
        private static void Function(string ZipCode)
        {
            var factory = new ConsoleAppFactory();
            var context = factory.CreateDbContext();
            var result  =
                context.FUNCResult.FromSqlRaw($"select * from TestFunction(\'{ZipCode}\')");

            foreach (var r in result)
            {
                Console.WriteLine($"{r.Id}");
            }
        }
Beispiel #5
0
        private static void Insert()
        {
            Console.WriteLine("Inserting");
            var factory    = new ConsoleAppFactory();
            var context    = factory.CreateDbContext();
            var postalCode = new PostalCode {
                Code = "Test code"
            };
            var street = new Street {
                Name = "Test street", PostalCodes = new List <PostalCode> {
                    postalCode
                }
            };

            context.PostalCodes.Add(postalCode);
            context.Streets.Add(street);
            var result = context.SaveChanges();

            Console.WriteLine("OK " + result);
        }