[英]Unable to cast object of type 'system.string' to type 'system.Byte[]' when trying to download a file from database
[英]Convert HierarchyId to string - unable to cast object of type 'System.Byte[]' to type 'System.String'
我在我的 EFCore3.1 中使用 HierarchyId,我在我的應用程序中將讀取和寫入分開,在讀取中,我創建了一個 Model,如下所示:
public class Category
{
public string Id { get; set; }
// removed for brevity
}
我應該提一下,在 write 中它工作正常。 這是我在寫作中使用的 model:
public class Category
{
public HierarchyId Id{ get; }
// removed for brevity
}
我需要在運行我的應用程序時出現以下錯誤:
無法將“System.Byte[]”類型的 object 轉換為“System.String”類型。
有沒有辦法將 HierarchyId 轉換為字符串?
編輯:我使用entityframeworkcore.sqlserver.hierarchyid package。
這是我必須做的:
builder.Property( x => x.Id )
.HasConversion(
v =>HierarchyId.Parse( v ),
v => v.ToString() ) ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.