DocumentDB 接口属性
DocumentDB Interface Properties
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
};
};
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
};
};