Support SQL Server HierarchyId data type

Topics: EF Runtime, General
Dec 21, 2012 at 11:15 PM
Edited Dec 25, 2012 at 6:22 PM

There is an open WorkItem about HierarchyId in the issue tracker: http://entityframework.codeplex.com/workitem/128

I needed this feature too, so I implemeted it in my own fork:

http://entityframework.codeplex.com/SourceControl/network/forks/zgabi/EntityFrameworkHierarchyId (comment: HierarchyId support added)

I would appreciate if this modification was merged into the main branch with a contribution.

Developer
Dec 21, 2012 at 11:25 PM

Hi zgabi,

We would welcome a contribution in this area. Before we can look at your code you will need to submit a Contributor License Agreement (CLA) as described here: http://entityframework.codeplex.com/wikipage?title=Contributing

We will also need to review the design and API and work with you if there need to be any changes. It would be very useful if you could give a brief description of what you have added in terms of public API and how you expect it to be used. (This may be obvious from the code but I haven't looked at it yet due to the need for a CLA.)

Once we reach agreement on the design, API, tests, etc., then the normal process would be fore you to submit a pull request, which is also described in the link above.

I look forward to working with you on this!

Thanks,
Arthur

Dec 22, 2012 at 12:16 AM
Edited Dec 22, 2012 at 12:27 AM

Hi Arthur,

Tomorrow I'll print/sign/scan and send the CLA.

I have added a new public class (HierarchyId), which is almost the same as the SqlHierarchyId class, but I didnt want to add refenrece to the Microsoft.SqlServer.Types assembly. (But tt is very easy to add a reference to that assembly and use the original SqlHierarchyId class instead of HierarchyId class)

The implementation of the HierarchyId type is very similar to the implementation of the DbGeometry and DbGeography types.

Example:

Code first model:

public class Table1
{
    public int Id { get; set; }
    public HierarchyId Path { get; set; }
}

public class MyContext : DbContext
{
    public DbSet<Table1> Table1 { get; set; }
}
How to use:
  
var items = c.Table1.OrderByDescending(o => o.Path).ToArray();

foreach (var table1 in items)
{
   Console.WriteLine(table1.Id + " " + table1.Path);
}

output:

4 /2/
3 /1/2/
2 /1/1/
1 /1/
var items = c.Table1.Where(o=>o.Path.IsDescendantOf(new HierarchyId("/1/")) == 1).Select(
    o => new
        {
            Id = o.Id,
            OrigPath = o.Path,
            Path = o.Path.GetReparentedValue(new HierarchyId("/1/"), HierarchyId.GetRoot()),
            Level = o.Path.GetLevel()
        }).ToArray();


foreach (var table1 in items)
{
    Console.WriteLine(table1.Id + "; " + table1.OrigPath + "; " + table1.Path + "; " + table1.Level);
}

output:

1; /1/; /; 1
2; /1/1/; /1/; 2
3; /1/2/; /2/; 2

Thanks,

Gábor

Developer
Dec 22, 2012 at 12:22 AM

Hi Gábor,

Thanks for providing this information. Several important members of the team are on vacation at the moment. We will certainly discuss this in more detail as a priority after the holiday period and get back to you then. Having the signed CLA will make things much easier.

Thanks again,
Arthur

Dec 22, 2012 at 11:50 AM

Hi Arthur,

Ok, I'm on vacation, too. I checked the CLA and I can submit it only in January because I have to sign it with my employer. However I made this modification in my free time, and the commited codes are not related to my official work.

Gábor

Dec 23, 2012 at 11:57 PM

Just a thought - if HierarchyId is a new EDM type (I did not look at the code), wouldn't it require revving CSDL (and as a result all other artifacts)?

Dec 24, 2012 at 11:35 AM

I tried to use hierarchyid in CDSL, and it was working. I haven't modified the CSDL parsing.

I have created a changeset (temporary added to SpatialTest class) , could you please check it (without CLA)? It contains modifications only in FunctionalTest project.

http://entityframework.codeplex.com/SourceControl/network/forks/zgabi/EntityFrameworkHierarchyId/changeset/e88ede671f9c

When I run the DbQuery_SelectMany_with_TVFs_and_spatial_types_works function the result is:

1 SRID=4326;POINT (-122.31946 47.625112) Supplier1 /1/
10 SRID=4326;POINT (-122.341529 47.611693) Supplier10 /3/
11 SRID=4326;POINT (-122.352842 47.6186) Supplier11 /3/1/
...

 Both the insert (in SpatialNorthwindInitializer.cs) and the select works.

Dec 24, 2012 at 7:08 PM

I will wait for the CLA before I take a look.

Jan 11, 2013 at 7:56 AM

I sent the CLA.

Developer
Jan 12, 2013 at 12:03 AM

zgabi,

Thanks for submitting the CLA. One of the EF team members is going to look at your code and also do some broader thinking around the best way to support hierarchy IDs and will get back to you.

Thanks,
Arthur

Developer
Jan 23, 2013 at 6:48 PM

Hi zgabi,

We have spent some time on the EF team brainstorming what we think the best approach is for tackling hierarchy ID and other related features. The conclusions from these discussions are as follows:

  • It is currently hard for EF to support new data types because the Entity Data Model (EDM) needs to be updated to support each new type. There are times when adding types as first-class members of EDM adds enough value that it is worth doing all the work and reving the EDM version. However, there are also cases where the value of this is not high, and we believe that HierarchyID is probably one of these cases. In such cases we really want to make it easy to support new types without the EF internals having hard-coded information about those types. Instead we would need some form of extension points that can handle reading and converting from a data reader and also converting appropriately for updates. There probably also needs to be a way for the store model to handle the new type so that areas like Migrations can handle scaffolding for them.
  • The dependency we took on the SQL Types assembly for spatial is problematic in several ways—for example, different versions of the assembly, needing to download and install the assembly on the client machine even when the rest of EF is bin deployable, the dynamic binding, and so on. It may be that we need to use the SQL Types assembly for HierarchyID but it is not clear that this is the case.
  • It’s not clear what the most useful mappings are for hierarchy ID. Having a type like the one you added may be an approach we take, but it couples the application’s model assembly to EF, which is usually something we avoid. (I know that the spatial types do this as well, but this is a compromise we wish we could have avoided.) In line with the first bullet point, it would be good if the type we map to is not fixed. It may also be useful to map things like navigation properties over the hierarchical data, and in such cases maybe the HierarchyID itself can just be stored as a string property. We don’t necessarily need all of this to be done in a contribution, but whatever mapping we do choose should be flexible enough to handle such things in the future.
  • The schedule and work we have planned for EF6 doesn’t allow us the time to go deeply into the design for everything above. However, we do plan to return to it after EF6 is released. At that time we would like to re-engage with you if you are still interested and potentially take some of your code or any additional work you do in this area as a contribution.

In summary, we appreciate greatly the work you have done here and your desire to contribute to EF, but for now we’re going to hold off on the contribution until we have a bit more time to ensure that we’re creating the best underlying building blocks for this area. 

Thanks,
Arthur

Nov 14, 2013 at 3:48 PM
Edited Nov 14, 2013 at 3:49 PM
Hi guys, are there any updates on this feature?
It would be very useful to have HierarchyId in list of supported types.
I can help you with development in case it will speed-up process.

Tomas Jecha
MVP
Nov 14, 2013 at 4:27 PM
Hi Tomas,

There is no official HierarchyID support, yet but i created my own nuget package with HierarchyID support:
https://www.nuget.org/packages/EntityFrameworkWithHierarchyId/

Or you can build your own package if you don't trust in my dll:)
Source of the version 6.0.1:
https://entityframework.codeplex.com/SourceControl/network/forks/zgabi/EfHierarchyId?branch=hotfix-6.0.1

zgabi
Dec 24, 2013 at 8:25 AM
Hi, guys!
Can anybody tell me, please, how to make this fork works? I have install it via NuGet Package Manager Console (using Install-Package EntityFrameworkWithHierarchyId -Version 6.0.2 command). But when I try to import the database table, containig hierarchyid field, to the Entity Data Model component, error appears, that the hierarchyid data type doesn't supported in the current version of the Entity Framework! Looks like, my Visual Studio Express 2013 for Web didn't "see" installed package with EF with hierarchyid :-(
Can anybody help me, please, with this issue?
Dec 24, 2013 at 1:05 PM
Hi,

In the nuget package you can find only the entityframework dlls, the tools which you try to use in VS is the original EF tools. It not supports hierarchyid. So you can do the following:
remove hierarhyid columns from DB, generate the EF codefirst model with the official EF power tools. Add hierarhyid columns manually to the code first model.

zgabi
Dec 24, 2013 at 1:23 PM
Thank you, zgabi! I'll try solution, you offered!
Dec 24, 2013 at 4:22 PM
Edited Dec 24, 2013 at 4:25 PM
zgabi wrote:
Hi,

In the nuget package you can find only the entityframework dlls, the tools which you try to use in VS is the original EF tools. It not supports hierarchyid. So you can do the following:
remove hierarhyid columns from DB, generate the EF codefirst model with the official EF power tools. Add hierarhyid columns manually to the code first model.

zgabi
Zgabi, I'm sorry, but it's still doesn't work :( I try to add hierarchyid column, but there's no such type in my Visual Studio. May be I need to do some additional actions to correctly install EF with hierarchyid? There's my steps to add EF with hierarchyid:
  1. Create a new MVC4 project (Empty template, .NET Framework 4.5)
  2. Go to NuGet Package Manager Console
  3. Type "Install-Package EntityFrameworkWithHierarchyId -Version 6.0.2", press Enter
  4. I have following messages (I have a Russian interface, so I translate messages manually):
"EntityFrameworkWithHierarchyId 6.0.2" successfully installed.
Adding "EntityFrameworkWithHierarchyId 6.0.2" to MvcApplication1.
"EntityFrameworkWithHierarchyId 6.0.2" successfully added to MvcApplication1.
Further, there're several errors like this
Exception when call "LoadFrom" with "1" argument: "Can't load file or package "EntityFramework.PowerShell.Utility, Version=6.0.0.0, Culture=neutral, PublicKeyToken=6847f3395fc61b47" либо одну из их зависимостей. Сбой при проверке правильности строгого имени. (Исключение из HRESULT: 0x8013141A)"
C:\Users\keyssser ekssselle\SkyDrive\разработка\MvcApplication1\packages\EntityFrameworkWithHierarchyId.6.0.2\tools\EntityFramework.psm1:669 знак:62
  • $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Utility.dll))
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodException
That's all. After this I create a class Class1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MvcApplication1.Models
{
public class Class1
{
     HierarchyId tmp;    }
}
  1. Try to type Hierarchyid, but IntelliSence can't find this type. When I try to compile a project, error appears, that "HierarchyId type or assembly not found".
    Tell me, please, what's wrong in this scenario?
Dec 24, 2013 at 9:33 PM
I tried your steps, but I dont have any error message.
HierarchyId is in System.Data.Entity.Hierarchy namespace. Do you have gtalk or skype?
Btw: the dlls in 6.0.2 package are not signed, you have to sign them manually. The snk file is in the (EfHierarchyId's) repository.
Feb 11, 2014 at 7:38 AM
Edited Feb 11, 2014 at 8:34 AM
Hi Man
This is going to kill me I encountered with same error too.

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'EntityFramework.PowerShell.Utility,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=6847f3395fc61b47' or one of its dependencies. Strong name validation fai
led. (Exception from HRESULT: 0x8013141A)"
At D:\ 2012\Projects\ClassLibrary1\packages\EntityFrameworkWithHierarchyId.6.0.2\tools\EntityFramework.psm1:669 char:62
  • $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Ut
    ility.dll))
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At D:\ 2012\Projects\ClassLibrary1\packages\EntityFrameworkWithHierarchyId.6.0.2\tools\EntityFramework.psm1:670 char:50
  • $dispatcher = $utilityAssembly.CreateInstance <<<< (
    • CategoryInfo : InvalidOperation: (CreateInstance:String) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework.PowerShell
, Version=6.0.0.0, Culture=neutral, PublicKeyToken=6847f3395fc61b47' or one of its dependencies. Strong name signature co
uld not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the corr
ect private key. (Exception from HRESULT: 0x80131045)"
At D:\ 2012\Projects\ClassLibrary1\packages\EntityFrameworkWithHierarchyId.6.0.2\tools\EntityFramework.psm1:698 char:31
  • $domain.CreateInstanceFrom <<<< (
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodException
Where is snk file to sign this dll I couldn't find repository or snk file.
I hope you give me reply soon because its urgent.
Feb 11, 2014 at 7:40 AM
Where is this snk file and also repository I couldn't find anything...
Feb 11, 2014 at 7:58 AM
Hi,

The snk file is here: https://entityframework.codeplex.com/SourceControl/network/forks/zgabi/EfHierarchyId/changeset/view/99489bd70239c8c96708da10e89481bb96ab7c22#src/
EcmaPublicKey.snk. (This is not the original ecma public key, it is my own snk file, which contains the private key, too)

Or you can try to use the latest ("unstable") version (https://www.nuget.org/packages/EntityFrameworkWithHierarchyId/6.1.0-pre1). It is already signed.
I can send you my EFTools version, too, if you want to generate models (which contains hierarchyid) from database.
Feb 11, 2014 at 8:32 AM
Edited Feb 11, 2014 at 8:33 AM
zgabi wrote:
Hi,

The snk file is here: https://entityframework.codeplex.com/SourceControl/network/forks/zgabi/EfHierarchyId/changeset/view/99489bd70239c8c96708da10e89481bb96ab7c22#src/
EcmaPublicKey.snk. (This is not the original ecma public key, it is my own snk file, which contains the private key, too)

Or you can try to use the latest ("unstable") version (https://www.nuget.org/packages/EntityFrameworkWithHierarchyId/6.1.0-pre1). It is already signed.
I can send you my EFTools version, too, if you want to generate models (which contains hierarchyid) from database.
Hi man thanks a lot I installed unstable version its work well. I test it :
CREATE TABLE [dbo].[Clas] (
[ClasId] INT                 IDENTITY (1, 1) NOT NULL,
[fff]    [sys].[hierarchyid] NULL,
CONSTRAINT [PK_dbo.Clas] PRIMARY KEY CLUSTERED ([ClasId] ASC)
  );
Its created from my db code first model.
Feb 12, 2014 at 1:09 PM
Edited Feb 12, 2014 at 2:16 PM
hi man
I hope you be good I have a problem with this mainly problem is how to use it?
---w1
---w2
---w3
------w31
------w32
------w33
-----------w331
-----------w332
-----------w334
-----------------w3341
-----------------w3342
---w4
---w5
This is my structure. At beginning I have query for reading all parent then (w1,w2,w3,w4 and w5) I have a column in my datable that which row is parent. Then I want to read all of the node children at the same time for example for w3:
------w31
------w32
------w33
-----------w331
-----------w332
-----------w334
-----------------w3341
-----------------w3342

Performance is very important. I have one table only but it will have a n million records with at least 10 level, so how can I make index based on HierarchyId field too to have a better performance.

Thanks
Feb 12, 2014 at 2:39 PM
I wrote an exampel earlier:
            foreach (var table1 in c.Employees.Where(x => x.Node.IsDescendantOf(HierarchyId.Parse("/1/"))))
            {
                Console.WriteLine(table1.EmployeeId + " " + table1.Name + " " + table1.Node);
            }
Result:
2 Emp1 /1/
4 Emp3 /1/1/
5 Emp4 /1/1/1/
7 Emp6 /1/2/

About indexes: it is not EF specific you can use the same indexes.
Feb 12, 2014 at 7:19 PM
Hi
Yes but it had problem on where condition I fixed it
      
               

               var items = db.Comments.Where(o => o.Position.IsDescendantOf(new HierarchyId(path))).Select(
                    o => new
                   {
                      // Id = o.CommentId,
                       OrigPath = o.Position,
                     //  Path = o.Position.GetReparentedValue(new HierarchyId(path), HierarchyId.GetRoot()),
                      // Level = o.Position.GetLevel()
                   }).ToArray();

                foreach (var t in items)
                {
                    Console.WriteLine(t.OrigPath);
                } 
            
    
    
Anyway, thank you it was big help.
Mar 6, 2014 at 11:19 AM
Hi!

I have the problem with running HierarchyID support in my MVC5 project. :(

This part of code throws System.NotSupportedException exception.
(The specified type member 'PathId' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.)
public ActionResult Index()
{
   var items = db.Categories.OrderByDescending(o => o.PathId).ToArray();
   return View(items);
}
Definition in edmx file:
namespace Administration.Models
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Hierarchy;
    
    public partial class Category
    {
        public Category()
        {
            this.CategoriesParameters = new HashSet<CategoriesParameter>();
            this.Products = new HashSet<Product>();
        }
    
        public int Id { get; set; }
        public HierarchyId PathId { get; set; }
        public string PageTitle { get; set; }
        public string PageDescription { get; set; }
        public string PageKeywords { get; set; }
        public string Name { get; set; }
        public string Culture { get; set; }
        public bool IsEnabled { get; set; }
    
        public virtual ICollection<CategoriesParameter> CategoriesParameters { get; set; }
        public virtual ICollection<Product> Products { get; set; }
    }
}
Installed: EntityFramework.HierarchyId 6.1.0-pre3

Thank you for your help.
Jiri
Mar 6, 2014 at 7:39 PM
Hi,

I was not able to reproduce your problem. Please could you send me a whole simplified project? +Database create script

zgabi
Mar 7, 2014 at 9:12 AM
Hi zgabi,

thank you for fast reply. I have sent you the download link via PM.

This is step by step, what i do (VS 2013):
  1. New project - ASP.NET Web Application - MVC
  2. Models - Add - ADO.NET Entity Data Model "HidTestModel" - Generate from database
    (hierarchyId is ignored by generator - OK)
  3. PM> Install-Package EntityFrameworkWithHierarchyId -Pre
  4. Manually add hierarchyId field to Category.cs
  5. Add the query to HomeController.cs
  6. Run project - it throws System.NotSupportedException exception.

And second issue:
  1. It seems that there is some collision between Microsoft.AspNet.Identity.EntityFramework and EntityFrameworkWithHierarchyId.
    File: Models - IdentityModels.cs
    ApplicationDbContext - throws EntityFramework assembly not referenced error during compilation
    When EntityFrameworkWithHierarchyId is uninstalled it works fine.
Mar 24, 2014 at 1:02 PM
zgabi wrote:
Hi,

I was not able to reproduce your problem. Please could you send me a whole simplified project? +Database create script

zgabi
Hi zgabi
There is a problem with it,
It couldn't be used with the new Identity system of Asp.net

VS 2013, EFHier..6.1, MVC 5.1

The Assembly Microsoft.AspNet.Identity.EntityFramework is tied to the guid of the original EF.

If you or anyone found any solution please share it with us, thanks...
Mar 24, 2014 at 1:11 PM
Hi Heelsa,

You can disassemble the Identity dll with ildasm, modify the publickeytoken of the referenced EF, and compile again with ilasm. It is a little hack, and i don't know whether it is legal or not. I haven't tried it, but it should work.
Mar 24, 2014 at 1:12 PM
Edited Mar 24, 2014 at 1:13 PM
Hi wntcz,

I've sent you the problem in your project on 7th of March to your email address. Is everything ok now?
Mar 24, 2014 at 1:18 PM
zgabi wrote:
Hi Heelsa,

You can disassemble the Identity dll with ildasm, modify the publickeytoken of the referenced EF, and compile again with ilasm. It is a little hack, and i don't know whether it is legal or not. I haven't tried it, but it should work.
Thanks mentioning this, I did a similar activity :D actually with refle.ctor, I've built a new version using EFHier... as a reference, not sure exactly about the problem but still there's something wrong there, I'm getting some kinda assembly manifest exception, "Could not load file or assembly 'EntityFramework',
If I managed this problem I'll let you know, and if you did this please providethe hacky-version of the 'EF...Identity' file. thanks.
Mar 24, 2014 at 2:41 PM
Done. Thanks...
Feb 26, 2015 at 3:17 PM
Hi,

I need use EntityFramework.Extended with EntityFrameworkWithHierarchyId, but i have some errors.
When i use EntitityFramework 6.1.x i don't have any problem, but when i install EntityFrameworkWithHierarchyId i see the following error:
"'WebApplication.Models.DB_POC_Auditoria_CadgContext' does not contain a definition for 'BeginAudit' and the best extension method overload 'EntityFramework.Extensions.AuditExtensions.BeginAudit(System.Data.Entity.Core.Objects.ObjectContext, EntityFramework.Audit.AuditConfiguration)' has some invalid arguments D:\Projetos\EntityFrameworkExtended\POC_Audit_Entity\WebApplication\Models\DB_POC_Auditoria_CadgContext.cs".

Thanks,

Thayson
Feb 26, 2015 at 4:25 PM
Hi thayson_f,

EntityFrameworkWithHierarchyId is not an official EF package, so it has different public key token.
EntityFramework.Extended works with the official EF only.
So if you want to use EntityFramework.Extended, you should change the public key token of the refereced EF in EF.Extended.

You can do it in the following way:
  • Decompile EF.Extended with ildasm
    "c:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\ildasm.exe" EntityFramework.Extended.dll
  • Change the public key token for the assembly reference of EF
    from:
    .assembly extern EntityFramework
    {
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
    .ver 6:0:0:0
    }
to:
.assembly extern EntityFramework
{
.publickeytoken = (68 47 F3 39 5F C6 1B 47 )
.ver 6:0:0:0
}
  • Remove the strong name from EF.Extended (remove the following lines)
    .publickey = (00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 // .$..............
            00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00   // .$..RSA1........
            3D 79 B4 C6 A5 5E FC D9 67 12 4F 16 89 97 3C 70   // =y...^..g.O...<p
            6F 25 EF 89 16 BC C1 95 25 CC 6D 13 62 5F 00 98   // o%......%.m.b_..
            01 88 8A 5E 94 EA 78 36 45 37 A9 73 E5 25 C0 41   // ...^..x6E7.s.%.A
            3E 0A 2E CB 41 5D 69 0A 21 F4 C0 4E 56 A1 E6 58   // >...A]i.!..NV..X
            D7 44 86 29 57 14 46 37 CF 64 2F 89 CA F9 71 85   // .D.)W.F7.d/...q.
            BB 4C 5B 46 05 1D E4 CB 31 5A CE 15 65 48 C7 A2   // .L[F....1Z..eH..
            F0 E6 23 40 05 A8 CB B7 6B 75 32 67 7B 2A 4F B5   // ..#@....ku2g{*O.
            CB DA 1D EB CD 30 C9 16 E8 7E 38 DE EF F9 18 C7 ) // .....0...~8.....
    .hash algorithm 0x00008004
  • Compile it again:
    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ilasm.exe EntityFramework.Extended.il /dll
  • Make sure that you use the modified dll in your project.
After this hack it seems to work.

Sorry, but I don't know any better solution:(

zgabi
Mar 12, 2015 at 1:58 PM
Hi
I have a problem can you help me?
I successfully installed EntityFrameworkWithHierarchyId through NuGet
but I received this error :
Error 1 The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

How do I fix this error?

I want to use EntityFrameworkWithHierarchyId in order to work with jqgrid and some of my tables have HierarchyID data types so I couldnt use ADO
Mar 12, 2015 at 2:26 PM
Please read my previous post. You need to modify the assembly which references the official EntityFramework (PublikKeyToken = b77a5c561934e089)
Dec 7, 2015 at 5:03 PM
Edited Dec 7, 2015 at 5:18 PM
Hello,

I have just installed EntityFrameworkWithHierarchyId using Nuget.

I have found no documentation how to use it. Can you provide a link to documentation or examples?

Specifically, I have a "Code First from database" and try to edit an entity class to manually add a HierarchyId property.

The HierarchId type is not found.

I have tried adding "using System.Data.Entity.Hierarchy", but it is no recognized. What am I doing wrong?

I also notice that there is no new reference in my project to anything about "hierarchyid", but NuGet shows that the EnityFramwordWithHierarchyId package is install in this project.

Suggestions how to proceed? Or other info you need?

EDIT: I am using Visual Studio 2015, in case that makes a difference. Target .net is 4.5.

EDIT#2: I think maybe EntityFrameworkWithHierarchyId is a replacement for regular EntityFramework, yes? If so, what are the correct steps to remove EntityFramework and replace with EntityFrameworkWithHierarchyId? (maybe there is no trick to thist, I am already trying things)

EDIT#3: (Solution?) Looks like I was correct in Edit#2... I uninstalled both, and then installed only EntityFrameworkWithHierarchyId, and it now recognizes the HierarchyId type.

Thanks!

p.s. Is this the best way, best place to ask questions?
Dec 7, 2015 at 5:32 PM
Hi,

Sorry, there is no documentation. You can use the documentation of the official EntityFramework, this is only a small "extension" (technically it is a fork, and replaces the whole official EF)
Here are some examples:

EntityFrameworkWithHierarchyId is not compatible with the official EntityFramework. Was it also installed? You should add reference to my EntityFramework.dll (public key token=6847f3395fc61b47), not to the official one.


2015-12-07 18:03 GMT+01:00 greylander <[email removed]>:

From: greylander

Hello,

I have just installed EntityFrameworkWithHierarchyId using Nuget.

I have found no documentation how to use it. Can you provide a link to documentation or examples?

Specifically, I have a "Code First from database" and try to edit an entity class to manually add a HierarchyId property.

The HierarchId type is not found.

I have tried adding "using System.Data.Entity.Hierarchy", but it is no recognized. What am I doing wrong?

I also notice that there is no new reference in my project to anything about "hierarchyid", but NuGet shows that the EnityFramwordWithHierarchyId package is install in this project.

Suggestions how to proceed? Or other info you need?

Thanks!

p.s. Is this the best way, best place to ask questions?

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Dec 7, 2015 at 6:01 PM
Thanks for the fast reply!

I did have regular EntityFramework installed first.

After I uninstalled both, then installed EntityFrameworkWithHierarchyId it now appears to work.

Is there any support for "from database"? (I guess I will find out soon when I try it)
Dec 7, 2015 at 7:01 PM
If I have EntityFrameworkWithHierarchyId installed (but not EnitityFramework), then when I try to do "Code first from Database" I get the error:
   The EntityFramework package is not installed on project
Does EntityFrameworkWithHierarchyId not support "from Database" at all? I thought as a minor extension, it would otherwise work the same as regular EntityFramework.

Is the only way to use this with "Code first from Database" to first install regular EntityFramework, then add/update with "Code first from Database", then uninstall regular EntityFramework, then install EntityFrameworkWithHierarchyId ?

Is there a better way?
Dec 7, 2015 at 8:30 PM
A modified version of EFTools is also needed to be able to generate EF model from database. Earlier I built it for VS2012 and 2013, but currently I don't have it.
The source code is in Codeplex, if you have time, you can try to build it:


Dec 7, 2015 at 9:19 PM
I'm not sure I have time to do that.

Would this workaround be effective? Or are there hidden problems with this?
  1. (for update only) Uninstall EntityFrameworkWithHierarchyId
  2. Install EntitfyFramework (regular)
  3. Do "Code First from Database" (either new or update)
  4. Uninstall EntityFramework (regular)
  5. Install EntityFrameworkWithHierarchyId
  6. Manually edit classes to include HierarchyId properties (best to use partial class in a separate file, so updates do no erase prior changes)
Dec 8, 2015 at 2:03 AM
When installing EntityFrameworkWithHierarchyId6.1.3 with NuGet, the output window indicates success, but I get the following error message, repeated many times for different types.

These errors seem to be generated by the EntityFrameworkWithHierarchyId.6.1.3\tools\init.ps1 script:
Executing script file 'D:\repos\................................................\packages\EntityFrameworkWithHierarchyId.6.1.3\tools\init.ps1'...
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(32) : Error in type "__System.Xml.XmlNode__": Exception: Cannot create a code method because of the method format. The method should be public, static, and have one parameter of type PSObject.
The first few types are System.Xml.XmlNode, System.Xml.XmlNodeList, System.DirectoryServices.PropertyValueCollection, System.DirectoryServices.DirectoryEntry and so on.

Then there are many errors like this:
There were errors in loading the format data file: Microsoft.PowerShell.Core, Error at XPath /Configuration/Controls/Control[1]/CustomControl/CustomEntries/CustomEntry[1]/CustomItem/Frame[1]/CustomItem/Text[1] in file C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Certificate.format.ps1xml: Resource FileSystemProviderStrings in assembly C:\System.Management.Automation is not found.
Despite the above errors, the output concludes with a success message:
Executing script file 'D:\repos\................................\packages\EntityFrameworkWithHierarchyId.6.1.3\tools\install.ps1'...

Type 'get-help EntityFramework' to see all available Entity Framework commands.
Successfully installed 'EntityFrameworkWithHierarchyId 6.1.3' to Trac.EntityModel_CffD
Should I trust that it was installed successfully?
Dec 8, 2015 at 7:32 AM
Sorry, I don't know. I created this package, because needed the hierarchyid support 3 years ago. But I haven't used this package since a year ago. I updated it to 6.1.3 only because somebody asked me.

Dec 8, 2015 at 7:32 PM
Thanks. So I guess it is not under active development at all then?

Does the listing of "Microsoft" as an author mean anything on the nuget page?

https://www.nuget.org/packages/EntityFrameworkWithHierarchyId/6.1.3

Or is that just because it is a fork of EF?
Dec 8, 2015 at 7:59 PM
It is because it is a fork, most of the code comes from MS:)
I don't know what is the legal way in this case, if somebody from MS writes me to remove it, I'll remove Microsoft from the author list.
Dec 13, 2015 at 1:48 PM
Hi,

You can download the modified version of EFTools from the following url:
http://goliat.eik.bme.hu/~zgabi/EfTools_HierarchyId_VS2015Update1.zip

With this you can generate the code first model from DB (with hierarchyid columns)

First you should uninstall the official EFTools.
Dec 15, 2015 at 12:42 AM
Hi,

I really appreciate your taking the time. This does not seem to work though.

I understand you might not have time to fix this, but just fyi...

After installing that version of the EF tools, when Visual Studio loads, it generates this error:
CreateInstance failed for package [Microsoft.Data.Entity.Design.BootstrapPackage.BootstrapPackage, Microsoft.Data.Entity.Design.BootstrapPackage, version=14.0.0.0, Culture=neutral, 

Could not load file or assembly 'Microsoft.Data.Entity.Design.BootstrapPackage, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
A related error occurs if attempt to add item "EF 6.s DbContext Generator" (ass soon as click "Add" from "Add New Item" dialog).
Dec 15, 2015 at 7:43 AM
Hi,

Please execute the following command from an administrator command prompt on you developer machine:
sn -Vr *,b03f5f7f11d50a3a

You can find the sn.exe here:
c:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools
or similar (please endure that you execute the 32 bit version, not from the x64 folder)

I'll fix this issue later.