SQL data reader exception when querying spatial data EF 6

14 views Asked by At

I am using EF 6 and .NET 4.8. I have a model class Project:

public int Id { get; set; }
public string Name { get; set; }
public DBGeography Area { get; set; }
public string AreaCoordinates { get; set; }

In the save method, a value for Area field is generated from the Area Coordinates provided by the user.

var text = ($"POLYGON(({source.AreaCoordinates}))");
var polygon = DbGeography.FromText($"{text}");

This is saved successfully in the database.

When I try to run a LINQ query on the Area property. For example:

var projects = dbContext.Projects.Where(x => x.Area != null).ToList();

I get an exception:

SQLDataReaderException: Spatial readers can only be produced from readers of type SqlDataReader. A reader of type EFCache.CachingReader was provided.

I am unable to proceed at this time, not sure why this error is coming up.

0

There are 0 answers