4

What I need to do, I have a comment table using the HierarchyID data type in sql server, and would like that mapped over to a Code First/EF 4.3 class. How can I achieve this?

Also how do I interact with the hierarchyID when inserting/deleting. Thank you very much.

Phil
  • 42,255
  • 9
  • 100
  • 100
gh9
  • 10,169
  • 10
  • 63
  • 96

2 Answers2

4

This is a possible duplicate of HierarchyID in Entity Framework not working

EF does not support that data type http://thedatafarm.com/blog/data-access/sql-server-2008-data-types-and-entity-framework-4/

Community
  • 1
  • 1
Thomas Jones
  • 4,892
  • 26
  • 34
0

I'm not used to the data type, but I've carried out some investigations.

Seems like this type is supported only inside the SQL Server both natively and in hosted CLR. Getting it outside requires it to be converted to a string (see Data Type Conversion section here).

I think the only way is creating a view in the database converting the hierarchyid to nvarchar(4000). To make it updatable you can either define a set of insert/update/delete triggers for that view, or create a set of corresponding stored procedures and map them to the EF context. I don't remember if EF Code First is capable of using SPs for modification operations, but an updatable view should be fine since it looks like an ordinary table.

Hope this helps.

Pavel Gatilov
  • 7,579
  • 1
  • 27
  • 42