1

I'm working with EF Core 3.1 and i use sql server datatype hierarchyid on one of my tables.

When i scaffold the table into my project the 'hierarchyid' turns into Geometry type.

I tried manually changing into SqlHierarchyId type with the help of dotMorten.Microsoft.SqlServer.Types package.

Code in my API :

[HttpGet]
[Route("")]
public ActionResult<List<EntityDto>> Get()
{
   EntityRepository repo = new EntityRepository (_context);
   var reults = repo.GetAll().ToList(); // <-- fails here
   return _mapper.Map<List<Entity>, List<EntityDto>>(reults);
}

GetAll() returns this :

protected DbSet<TEntity> dbSet;

public virtual IQueryable<TEntity> GetAll()
{
   return dbSet;
}

But when I try to get the list of this entities i get an error :

Unable to cast object of type 'Microsoft.SqlServer.Types.SqlHierarchyId' to type 'Microsoft.Data.SqlClient.Server.IBinarySerialize'.

I didn't find any way to overcome this error.

Thanks for helping.

Shai Barak
  • 129
  • 8
  • 3
    Maybe you can use this package? https://www.nuget.org/packages/EntityFrameworkCore.SqlServer.HierarchyId – ErikEJ Apr 26 '20 at 15:21
  • I can't believe i never saw this package, i was searching for so long, it works like a charm, Thank you so much ! – Shai Barak Apr 26 '20 at 15:59

0 Answers0