实体框架核心层次结构ID [英] Entity Framework Core hierarchyid

查看:64
本文介绍了实体框架核心层次结构ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EF Core,但我需要在其中一张表上使用sql server数据类型 hierarchyid

I'm trying to use EF Core but I need to use the sql server datatype hierarchyid on one of my tables.

是否可以将我的c#类中的字段指定为hierarchyid类型?

Is it possible to designate a field in my c# class to be of type hierarchyid?

我可以手动列EF创建为 hierarchyid 类型而又不破坏EF?

Could I manually column EF creates to be type hierarchyid without breaking EF?

编辑:
我尝试过

I have tried to do this:

public class Entity
{
    public int Id { get; set; }
    public string Name { get; set; }
    public SqlHierarchyId HierarchyId { get; set; }
}

由于建议该功能受EF core 2.1支持,但是当我运行add-migration我收到此错误:

As it's suggested that this is supported by EF core 2.1, however when i run add-migration I get this error:

The current CSharpHelper cannot scaffold literals of type 'Microsoft.SqlServer.Types.SqlHierarchyId'. Configure your services to use one that can.


推荐答案

对于那些寻找SqlHierarchyId包的Nuget包的人在其中,它在 Microsoft.SqlServer.Types 中。

For those looking for the Nuget Package which the SqlHierarchyId package is in, it's in Microsoft.SqlServer.Types.

请注意,程序包信息说此程序包包含DbGeography和DbGeometery类型,但它还包含SqlHierarchyId类型。

Note that the package info says this package contains the DbGeography and DbGeometery types, but it also contains the SqlHierarchyId type.

还要注意,该类是 SqlHierarchyId ,而不是 HierarchyId (就像我一直在寻找)。

Also note the class is SqlHierarchyId, not HierarchyId (like I was looking for).

这篇关于实体框架核心层次结构ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆