using Microsoft.SqlServer.Types;
using Newtonsoft.Json.Serialization;
public static void Main()
Console.WriteLine("Hello SqlGeography");
static DataTable GetGeoTable()
DataTable dataTable = new DataTable("table");
dataTable.Columns.Add("f1", typeof(SqlGeography));
dataTable.Columns.Add("id", typeof(int));
DataRow newRow = dataTable.NewRow();
newRow["f1"] = SqlGeography.Point(20, 10, 4326);
dataTable.Rows.Add(newRow);
newRow = dataTable.NewRow();
newRow["f1"] = SqlGeography.Point(30, 15, 4326);
dataTable.Rows.Add(newRow);
foreach (DataRow row in dataTable.Rows)
string ID = row["id"].ToString();
string f1 = row["f1"].ToString();
Console.WriteLine("{0} {1}", ID, f1);
static string SerializeToJson(DataTable dt)
ITraceWriter traceWriter = new MemoryTraceWriter();
var options = new JsonSerializerSettings
Formatting = Newtonsoft.Json.Formatting.Indented,
TraceWriter = traceWriter,
var json = JsonConvert.SerializeObject(dt, options);
Console.WriteLine(traceWriter);