Azure cosmosdb DocumentDB接口属性

Azure cosmosdb DocumentDB接口属性,azure-cosmosdb,Azure Cosmosdb,DocumentDb是否足够智能,能够正确地存储和管理作为接口的文档上的属性?MongoDb通过将类型存储在服务器上文档内的字段中,很好地处理了这个问题 public class Customer { public string Name{get;set;} // Does this work correctly when saving and retrieving? public IPolicy Policy{get;set;} } public interface

DocumentDb是否足够智能,能够正确地存储和管理作为接口的文档上的属性?MongoDb通过将类型存储在服务器上文档内的字段中,很好地处理了这个问题

public class Customer
{
    public string Name{get;set;}

    // Does this work correctly when saving and retrieving?
    public IPolicy Policy{get;set;}
}

public interface IPolicy
{
    decimal Rate{get;set;}
}

public MagicPolicy : IPolicy
{
    public decimal Rate{get;set;}
}

public SuperPolicy : IPolicy
{
    public decimal Rate{get;set;}
    public string ImAnExtraProperty{get;set;}
}

答案是肯定的!但不是现成的。它使用Newtonsoft.Json进行序列化。因此,您可以通过调整序列化程序设置来实现神奇的效果:

JsonConvert.DefaultSettings = () =>
{
    return new JsonSerializerSettings()
    {
        TypeNameHandling = TypeNameHandling.Auto
    };
};

答案是肯定的!但不是现成的。它使用Newtonsoft.Json进行序列化。因此,您可以通过调整序列化程序设置来实现神奇的效果:

JsonConvert.DefaultSettings = () =>
{
    return new JsonSerializerSettings()
    {
        TypeNameHandling = TypeNameHandling.Auto
    };
};