1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace ProductivityApiTests
{
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Spatial;
public class SpatialNorthwindInitializer : DropCreateDatabaseAlways<SpatialNorthwindContext>
{
protected override void Seed(SpatialNorthwindContext context)
{
context.Database.ExecuteSqlCommand(
@"
CREATE FUNCTION [dbo].[fx_SuppliersWithinRange]
(
@miles int,
@location geography
)
RETURNS TABLE
AS
RETURN
(
SELECT [Id],[Name],[Location]
FROM [ProductivityApiTests.SpatialNorthwindContext].[dbo].[SupplierWithLocations] as supplier
Where supplier.Location.STIntersects(@location.STBuffer(@miles * 1609.344)) = 1
)"
);
context.Database.ExecuteSqlCommand(
@"
CREATE FUNCTION [dbo].[fx_SupplierLocationsWithinRange]
(
@miles int,
@location geography
)
RETURNS TABLE
AS
RETURN
(
SELECT [Location]
FROM [ProductivityApiTests.SpatialNorthwindContext].[dbo].[SupplierWithLocations] as supplier
Where supplier.Location.STIntersects(@location.STBuffer(@miles * 1609.344)) = 1
)"
);
new List<SupplierWithLocation>
{
new SupplierWithLocation
{
Name = "Supplier1",
Location = DbGeography.FromText("POINT(-122.31946 47.625112)")
},
new SupplierWithLocation
{
Name = "Supplier2",
Location = DbGeography.FromText("POINT(-122.296623 47.640405)")
},
new SupplierWithLocation
{
Name = "Supplier3",
Location = DbGeography.FromText("POINT(-122.334571 47.604009)")
},
new SupplierWithLocation
{
Name = "Supplier4",
Location = DbGeography.FromText("POINT(-122.336124 47.610267)")
},
new SupplierWithLocation
{
Name = "Supplier5",
Location = DbGeography.FromText("POINT(-122.338711 47.610753)")
},
new SupplierWithLocation
{
Name = "Supplier6",
Location = DbGeography.FromText("POINT(-122.335576 47.610676)")
},
new SupplierWithLocation
{
Name = "Supplier7",
Location = DbGeography.FromText("POINT(-122.349755 47.647494)")
},
new SupplierWithLocation
{
Name = "Supplier8",
Location = DbGeography.FromText("POINT(-122.335197 47.646711)")
},
new SupplierWithLocation
{
Name = "Supplier9",
Location = DbGeography.FromText("POINT(-122.304482 47.647295)")
},
new SupplierWithLocation
{
Name = "Supplier10",
Location = DbGeography.FromText("POINT(-122.341529 47.611693)")
},
new SupplierWithLocation
{
Name = "Supplier11",
Location = DbGeography.FromText("POINT(-122.352842 47.6186)")
},
new SupplierWithLocation
{
Name = "Supplier12",
Location = DbGeography.FromText("POINT(-122.255949 47.549068)")
},
new SupplierWithLocation
{
Name = "Supplier13",
Location = DbGeography.FromText("POINT(-122.349074 47.619589)")
},
new SupplierWithLocation
{
Name = "Supplier14",
Location = DbGeography.FromText("POINT(-122.3381 47.612467)")
},
new SupplierWithLocation
{
Name = "Supplier15",
Location = DbGeography.FromText("POINT(-122.317575 47.665229)")
},
new SupplierWithLocation
{
Name = "Supplier16",
Location = DbGeography.FromText("POINT(-122.31249 47.632342)")
},
}.ForEach(s => context.Suppliers.Add(s));
new List<WidgetWithGeometry>
{
new WidgetWithGeometry
{
Name = "Widget1",
SomeGeometry = DbGeometry.FromText("POINT(-122.31946 47.625112)"),
Complex = new ComplexWithGeometry
{
NotGeometry = "1",
SomeMoreGeometry = DbGeometry.FromText("POINT(-122.31946 47.625112)")
}
},
new WidgetWithGeometry
{
Name = "Widget2",
SomeGeometry = DbGeometry.FromText("POINT(-122.296623 47.640405)"),
Complex = new ComplexWithGeometry
{
NotGeometry = "1",
SomeMoreGeometry = DbGeometry.FromText("POINT(-122.31946 47.625112)")
}
},
new WidgetWithGeometry
{
Name = "Widget3",
SomeGeometry = DbGeometry.FromText("POINT(-122.334571 47.604009)"),
Complex = new ComplexWithGeometry
{
NotGeometry = "1",
SomeMoreGeometry = DbGeometry.FromText("POINT(-122.31946 47.625112)")
}
},
new WidgetWithGeometry
{
Name = "Widget4",
SomeGeometry = DbGeometry.FromText("POINT(-122.336124 47.610267)"),
Complex = new ComplexWithGeometry
{
NotGeometry = "1",
SomeMoreGeometry = DbGeometry.FromText("POINT(-122.31946 47.625112)")
}
},
}.ForEach(w => context.Widgets.Add(w));
new List<WidgetWithLineString>
{
new WidgetWithLineString
{
AGeometricLineString = DbGeometry.FromText("LINESTRING (10 10, 100 100)")
},
new WidgetWithLineString
{
AGeometricLineString = DbGeometry.FromText("LINESTRING (100 100, 200 200)")
},
}.ForEach(w => context.LineStringWidgets.Add(w));
new List<WidgetWithPolygon>
{
new WidgetWithPolygon
{
AGeometricPolygon = DbGeometry.FromText("POLYGON ((50 70, 100 70, 100 20, 50 20, 50 70))")
},
new WidgetWithPolygon
{
AGeometricPolygon = DbGeometry.FromText("POLYGON ((150 170, 200 170, 200 120, 150 120, 150 170))")
},
}.ForEach(w => context.PolygonWidgets.Add(w));
}
}
}
|