public void CanUseGeomatryAsTextFunction()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });
                context.SaveChanges();

                var result = (from u in context.Distributors
                              select u.point.AsText()).ToList();

                foreach (var item in result)
                {
                    Assert.AreEqual("POINT(-122.336106 47.605049)", item);
                }

                context.Database.Delete();
            }
        }
        public void CanUseBufferFunction()
        {
            if (version < new Version(5, 6))
            {
                return;
            }

            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });
                context.SaveChanges();

                var result = (from u in context.Distributors
                              select u.point.Buffer(1212).AsText()).First();

                Assert.AreEqual("POLYGON((-122.336106 -1164.394951,-181.80612728483064 -1162.935043920669,-241.13288007942745 -1158.5588397267024,-300.17344103989853 -1151.2768810773146,-358.78557628354747 -1141.1067108487152,-416.8280840427558 -1128.0728298717872,-474.16113483240827 -1112.2066379074372,-530.6466083113708 -1093.5463580018213,-586.1484260264888 -1072.1369444036795,-640.5328792375019 -1048.0299742656134,-693.668951033109 -1021.2835233902063,-745.4286319621847 -991.9620263203299,-795.6872284197578 -960.1361211106848,-844.3236630448292 -925.8824791545416,-891.2207664063383 -889.2836204756372,-936.2655592745862 -850.4277149302104,-979.3495247980954 -809.4083697980955,-1020.3688699302104 -766.3244042745862,-1059.2247754756372 -721.2796114063383,-1095.8236341545417 -674.3825080448293,-1130.0772761106848 -625.7460734197579,-1161.9031813203298 -575.4874769621847,-1191.2246783902062 -523.727796033109,-1217.9711292656134 -470.5917242375019,-1242.0780994036795 -416.2072710264888,-1263.4875130018213 -360.7054533113708,-1282.1477929074372 -304.2199798324083,-1298.0139848717872 -246.8869290427558,-1311.0478658487152 -188.8444212835475,-1321.2180360773145 -130.2322860398985,-1328.4999947267024 -71.19172507942744,-1332.876198920669 -11.864972284830642,-1334.336106 47.605049,-1328.4999947267024 166.40182307942746,-1321.2180360773145 225.4423840398985,-1311.0478658487152 284.0545192835475,-1298.0139848717872 342.0970270427558,-1282.1477929074372 399.4300778324083,-1263.4875130018213 455.9155513113708,-1242.0780994036795 511.4173690264888,-1217.9711292656134 565.8018222375019,-1191.2246783902062 618.937894033109,-1161.9031813203298 670.6975749621847,-1130.0772761106848 720.9561714197579,-1095.8236341545417 769.5926060448293,-1059.2247754756372 816.4897094063383,-1020.3688699302104 861.5345022745862,-979.3495247980954 904.6184677980955,-936.2655592745862 945.6378129302104,-891.2207664063383 984.4937184756373,-844.3236630448292 1021.0925771545416,-795.6872284197578 1055.3462191106848,-745.4286319621847 1087.1721243203299,-693.668951033109 1116.4936213902063,-640.5328792375019 1143.2400722656134,-586.1484260264888 1167.3470424036796,-530.6466083113708 1188.7564560018213,-474.16113483240827 1207.4167359074372,-416.8280840427558 1223.2829278717873,-358.78557628354747 1236.3168088487153,-300.17344103989853 1246.4869790773146,-241.13288007942745 1253.7689377267025,-181.80612728483064 1258.145141920669,-122.336106 1259.605049,-62.86608471516936 1258.145141920669,-3.5393319205725504 1253.7689377267025,55.501229039898504 1246.4869790773146,114.1133642835475 1236.3168088487153,172.15587204275582 1223.2829278717873,229.4889228324083 1207.4167359074372,285.9743963113708 1188.7564560018213,341.47621402648883 1167.3470424036796,395.86066723750196 1143.2400722656134,448.99673903310907 1116.4936213902063,500.75641996218474 1087.1721243203299,551.0150164197579 1055.3462191106848,599.6514510448293 1021.0925771545416,646.5485544063383 984.4937184756373,691.5933472745862 945.6378129302104,734.6773127980955 904.6184677980955,775.6966579302104 861.5345022745862,814.5525634756373 816.4897094063383,851.1514221545416 769.5926060448293,885.4050641106849 720.9561714197579,917.2309693203299 670.6975749621847,946.5524663902063 618.937894033109,973.2989172656135 565.8018222375019,997.4058874036796 511.4173690264888,1018.8153010018214 455.9155513113708,1037.4755809074372 399.4300778324083,1053.3417728717873 342.0970270427558,1066.3756538487153 284.0545192835475,1076.5458240773146 225.4423840398985,1083.8277827267025 166.40182307942746,1088.203986920669 107.07507028483064,1089.663894 47.605049,1083.8277827267025 -71.19172507942744,1076.5458240773146 -130.2322860398985,1066.3756538487153 -188.8444212835475,1053.3417728717873 -246.8869290427558,1037.4755809074372 -304.2199798324083,1018.8153010018214 -360.7054533113708,997.4058874036796 -416.2072710264888,973.2989172656135 -470.5917242375019,946.5524663902063 -523.727796033109,917.2309693203299 -575.4874769621847,885.4050641106849 -625.7460734197579,851.1514221545416 -674.3825080448293,814.5525634756373 -721.2796114063383,775.6966579302104 -766.3244042745862,734.6773127980955 -809.4083697980955,691.5933472745862 -850.4277149302104,646.5485544063383 -889.2836204756372,599.6514510448293 -925.8824791545416,551.0150164197579 -960.1361211106848,500.75641996218474 -991.9620263203299,448.99673903310907 -1021.2835233902063,395.86066723750196 -1048.0299742656134,341.47621402648883 -1072.1369444036795,285.9743963113708 -1093.5463580018213,229.4889228324083 -1112.2066379074372,172.15587204275582 -1128.0728298717872,114.1133642835475 -1141.1067108487152,55.501229039898504 -1151.2768810773146,-3.5393319205725504 -1158.5588397267024,-62.86608471516936 -1162.935043920669,-122.336106 -1164.394951))", result);

                context.Database.Delete();
            }
        }
        public void CanGetCoordinatesFromGeometry()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });

                context.SaveChanges();

                var point = (from u in context.Distributors
                             select u.point).First();

                Assert.AreEqual(-122.336106, point.XCoordinate);

                Assert.AreEqual(47.605049, point.YCoordinate);

                var result = (from u in context.Distributors
                              select u.point.XCoordinate).ToList();


                foreach (var item in result)
                {
                    Assert.AreEqual(-122.336106, item);
                }
                context.Database.Delete();
            }
        }
        public void CanUseIsSimpleFunction()
        {
            if (version < new Version(5, 6))
            {
                return;
            }

            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)", 101),
                });

                context.SaveChanges();
                var result = (from u in context.Distributors
                              select u.point.IsSimple).ToList();

                foreach (var item in result)
                {
                    Assert.AreEqual(true, item);
                }

                context.Database.Delete();
            }
        }
        public void CanUseDimensionFunction()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });

                context.Distributors.Add(new Distributor()
                {
                    Name  = "School of Fine Art",
                    point = DbGeometry.FromText("POINT(-122.335197 47.646711)"),
                });

                context.SaveChanges();

                var dimensions = (from u in context.Distributors
                                  select u.point.Dimension).ToList();

                foreach (var item in dimensions)
                {
                    Assert.AreEqual(0, item);
                }

                context.Database.Delete();
            }
        }
        public void CanThrowExceptionForUnkownFunction()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });

                context.Distributors.Add(new Distributor()
                {
                    Name  = "School of Fine Art",
                    point = DbGeometry.FromText("POINT(-122.335197 47.646711)"),
                });

                context.SaveChanges();

                var myLocation = DbGeometry.FromText("POINT(-122.296623 47.640405)");

                var university = (from u in context.Distributors
                                  orderby u.point.Distance(myLocation)
                                  select u).FirstOrDefault();
            }
        }
        public void CanUseCreateProviderValueFunction()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });
                context.SaveChanges();

                var point = (from u in context.Distributors
                             select u.point).First();

                var geometryWellKnownValueWKT = new DbGeometryWellKnownValue()
                {
                    CoordinateSystemId = 0,
                    WellKnownBinary    = null,
                    WellKnownText      = "POINT(1 2)"
                };

                MySqlGeometry providerValue = (MySqlGeometry)spatialServices.CreateProviderValue(geometryWellKnownValueWKT);
                Assert.AreEqual("POINT(1 2)", providerValue.ToString());


                var geometryWellKnownValueWKB = new DbGeometryWellKnownValue()
                {
                    CoordinateSystemId = 0,
                    WellKnownBinary    = providerValue.Value,
                    WellKnownText      = null
                };

                MySqlGeometry providerValue_2 = (MySqlGeometry)spatialServices.CreateProviderValue(geometryWellKnownValueWKB);
                Assert.AreEqual("POINT(1 2)", providerValue_2.ToString());

                context.Database.Delete();
            }
        }
        public void CanUseSSContainsFunction()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });
                context.SaveChanges();

                var result = (from u in context.Distributors
                              select u.point).First();

                Assert.AreEqual(result.Contains(DbGeometry.FromText("POINT (1 1)")), false);

                context.Database.Delete();
            }
        }
        public void CanUseDistanceGeometryFunction()
        {
            using (DistribuitorsContext context = new DistribuitorsContext())
            {
                context.Database.Delete();
                context.Database.Create();

                context.Distributors.Add(new Distributor()
                {
                    Name  = "Graphic Design Institute",
                    point = DbGeometry.FromText("POINT(-122.336106 47.605049)"),
                });
                context.SaveChanges();

                var points = (from p in context.Distributors
                              select p.point);

                foreach (var item in points)
                {
                    Assert.AreEqual(0.0, DbGeometry.FromText("POINT(-122.336106 47.605049)").Distance(item));
                }
            }
        }