コード例 #1
0
        public void InsertMunicipailitiesFromShapeFile()
        {
            RemoveDistricts();

            var shapes = new DagiShapeFileReader().Read("..\\..\\..\\data\\KOMMUNE", "KOMNAVN");

            using (var context = new Context())
            {
                foreach (var shape in shapes)
                {
                    context.Features.Add(new Feature {
                        Name = shape.Key, Geography = shape.Value
                    });
                }
                context.SaveChanges();
            }
        }
コード例 #2
0
        protected override void Seed(Context context)
        {
            if (!context.Features.Any())
            {
                var assemblyDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
                var seedDataFilePath  = Directory.GetFiles(assemblyDirectory, "KOMMUNE.*", SearchOption.AllDirectories).First();
                var seedDataDirectory = Path.GetDirectoryName(seedDataFilePath);

                var shapes = new DagiShapeFileReader().Read(Path.Combine(seedDataDirectory, "KOMMUNE"), "KOMNAVN");

                foreach (var shape in shapes)
                {
                    context.Features.Add(new Feature {
                        Name = shape.Key, Geography = shape.Value
                    });
                }
                context.SaveChanges();
            }

            base.Seed(context);
        }