简体   繁体   中英

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:

System.InvalidOperationException: 'The property 'Order.Id' is of type 'OrderId' which is not supported by current database provider. Either change the property CLR type or manually configure the database type for it.'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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