简体   繁体   English

如何在Entity Framework Core 2.1中映射SQL_VARIANT?

[英]How to map SQL_VARIANT in Entity Framework Core 2.1?

In core 1.1 I used the TypeName = "sql_variant" attribute on the property and it worked. 在核心1.1版中,我在属性上使用了TypeName =“ sql_variant”属性,并且该属性有效。

[Column("tx_value", TypeName = "sql_variant")]
public string Value { get; set; }

I have migrated to core 2.1, started to return the error (The property 'EnterpriseDetails.Value' could not be mapped, because it is of type 'string' which is not a supported primitive type or a valid entity type. property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'). 我已迁移到核心2.1,开始返回错误(无法映射属性“ EnterpriseDetails.Value”,因为它的类型为“字符串”,这不是受支持的原始类型或有效的实体类型。属性,或忽略使用'[NotMapped]'属性或使用'OnModelCreating'中的'EntityTypeBuilder.Ignore')。 How to solve this? 如何解决呢?

Your syntax looks fine. 您的语法看起来不错。 The issue is that SQL_VARIANT does not map directly to a 'string' primitive type. 问题是SQL_VARIANT不会直接映射到“字符串”原始类型。 Since the data that can be populated in SQL_VARIANT is highly variable, you will need to use the object type. 由于可以在SQL_VARIANT中填充的数据是高度可变的,因此您将需要使用object类型。

[Column("tx_value", TypeName = "sql_variant")]
public object Value { get; set; }

More information on SQL_VARIANT from MS Docs . MS Docs提供了有关SQL_VARIANT的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM