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.

2 Answers 2

4
+100

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/

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.