我使用.NET Core創建了一個可重用的庫(針對.NETStandard 1.4),我使用的是Entity Framework Core(以及兩者都是新的)。我有一個看起來好像是實體類:如何將JSON存儲在EF Core的實體字段中?
public class Campaign
{
[Key]
public Guid Id { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }
public JObject ExtendedData { get; set; }
}
,我必須定義一個DbSet類的DbContext:
public DbSet<Campaign> Campaigns { get; set; }
(我也是用與DI Repository模式,但我不認爲,這是相關的)
我的單元測試給我這個錯誤:
System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'JToken.Parent' of type 'JContainer'. Either manually configure the relationship, or ignore this property from the model..
有沒有辦法來IND這是不是一種關係,但應該存儲爲一個大字符串?
我想你應該改變擴展數據類型爲字符串,然後存儲字符串JSON – Michael
@邁克爾我想過但我想確保它總是有效的JSON。 – Alex