You've already forked linux-packaging-mono
Imported Upstream version 5.2.0.179
Former-commit-id: a536d4f20e27294d8bbc2184d75f3a22364f7ba1
This commit is contained in:
parent
966bba02bb
commit
fad71374d0
74
external/entityframework/samples/Provider/SampleEntityFrameworkProvider/SpatialDataReader.cs
vendored
Normal file
74
external/entityframework/samples/Provider/SampleEntityFrameworkProvider/SpatialDataReader.cs
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Spatial;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.SqlTypes;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SampleEntityFrameworkProvider
|
||||
{
|
||||
internal sealed class SqlSpatialDataReader : DbSpatialDataReader
|
||||
{
|
||||
private readonly SqlDataReader reader;
|
||||
|
||||
static SqlSpatialDataReader()
|
||||
{
|
||||
}
|
||||
|
||||
public SqlSpatialDataReader(SqlDataReader underlyingReader)
|
||||
{
|
||||
this.reader = underlyingReader;
|
||||
}
|
||||
|
||||
public override DbGeography GetGeography(int ordinal)
|
||||
{
|
||||
EnsureGeographyColumn(ordinal);
|
||||
|
||||
var geographyBytes = this.reader.GetSqlBytes(ordinal);
|
||||
dynamic geography = Activator.CreateInstance(SqlTypes.SqlGeographyType);
|
||||
geography.Read(new BinaryReader(geographyBytes.Stream));
|
||||
|
||||
return SpatialServices.Instance.GeographyFromProviderValue(geography);
|
||||
}
|
||||
|
||||
public override DbGeometry GetGeometry(int ordinal)
|
||||
{
|
||||
EnsureGeometryColumn(ordinal);
|
||||
|
||||
var geometryBytes = this.reader.GetSqlBytes(ordinal);
|
||||
dynamic geometry = Activator.CreateInstance(SqlTypes.SqlGeometryType);
|
||||
geometry.Read(new BinaryReader(geometryBytes.Stream));
|
||||
|
||||
return SpatialServices.Instance.GeometryFromProviderValue(geometry);
|
||||
}
|
||||
|
||||
private void EnsureGeographyColumn(int ordinal)
|
||||
{
|
||||
string fieldTypeName = this.reader.GetDataTypeName(ordinal);
|
||||
if (!fieldTypeName.EndsWith("sys.geography", StringComparison.Ordinal)) // Use EndsWith so that we just see the schema and type name, not the database name.
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
string.Format(
|
||||
"Expected a geography value, found a value of type {0}.",
|
||||
fieldTypeName));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureGeometryColumn(int ordinal)
|
||||
{
|
||||
string fieldTypeName = this.reader.GetDataTypeName(ordinal);
|
||||
if (!fieldTypeName.EndsWith("sys.geometry", StringComparison.Ordinal)) // Use EndsWith so that we just see the schema and type name, not the database name.
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
string.Format(
|
||||
"Expected a geometry value, found a value of type {0}.",
|
||||
fieldTypeName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user