private static void BuildDatabase() { SpatialDataContext db = new SpatialDataContext(); if (db.Customers.Any()) { return; } string[] names = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" }; string[] lineStrings = { "LINESTRING(1 1, 3 3)", "LINESTRING(1 1, 3 3, 2 4, 2 0)", "LINESTRING(1 1, 3 3, 2 4, 2 0, 1 1)", "LINESTRING(1 1, 2 4, 3 9)", "LINESTRING(1 1 NULL 0, 2 4 NULL 12.3, 3 9 NULL 24.5)", "LINESTRING(2 1, 2 3)", "LINESTRING(3 2, 4 6)" }; var customers = Enumerable.Range(1, 7).Select(e => new Customer { Id = e, Name = names[e - 1], DbLocation = DbGeography.FromText(String.Format("POINT({0} {1} {2} {3})", e, e, e, e)), DbLineString = DbGeography.FromText(lineStrings[e - 1]) }); foreach (var customer in customers) { db.Customers.Add(customer); } db.SaveChanges(); }
public CustomersController(SpatialDataContext db) { _db = db; BuildDatabase(db); }