[英]How to manually configure the database type for a property in EF Core?
I have a class: 我有一堂课:
class Order
{
public OrderId Id {get;set;}
}
struct OrderId
{
private int readonly id;
public OrderId(int id)
{
this.id = id;
}
}
For some reason, I don't want to use a primitive type for the property. 由于某些原因,我不想为该属性使用原始类型。 When I'm trying to save object of this class to
Sql Server
through Entity Framework Core
, I get an error: 当我尝试通过
Entity Framework Core
将此类的对象保存到Sql Server
,出现错误:
System.InvalidOperationException: 'The property 'Order.Id' is of type 'OrderId' which is not supported by current database provider.
System.InvalidOperationException:'属性'Order.Id'的类型为'OrderId',当前数据库提供程序不支持。 Either change the property CLR type or manually configure the database type for it.'
要么更改属性CLR类型,要么为其手动配置数据库类型。”
Question: Is it possible to configure mapping in such a case and how to do it? 问题:在这种情况下是否可以配置映射以及如何配置?
EF Core(最新版本2.0)目前不支持此功能。有关跟踪问题和可能的解决方法,请参阅https://github.com/aspnet/EntityFramework/issues/9194
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.