[英]MongoDB document model code value type data in C# driver
I have a relational table that stores key-value data in the below structure. 我有一个关系表,该表在以下结构中存储键值数据。
KEY VARCHAR(10)
Value-Text VARCHAR(50)
Value-Date DATETIME
Value NUMERIC
So for any given key, there will be only one Value column used. 因此,对于任何给定的键,将只使用一个“值”列。 This is not a good design in first place.
首先,这不是一个好的设计。 If I have to create a similar key-value pair in mongo where the value field have different data types, what is the best option ?
如果必须在mongo中创建相似的键值对,其中value字段具有不同的数据类型,那么最佳选择是什么? How will it work with the C# driver ?
它如何与C#驱动程序一起使用?
As gypsyCoder mentioned, there is no need to store the type as part of the schema. 如gypsyCoder所述,无需将类型存储为模式的一部分。 In C#, you can define
value
as an object
in your POCO, and the driver will serialize the value as the underlying type. 在C#中,您可以将
value
定义为POCO中的object
,驱动程序会将值序列化为基础类型。 There are a few exceptions. 有一些例外。 For example, MongoDB does not support decimal types, so decimals are serialized as strings.
例如,MongoDB不支持十进制类型,因此十进制被序列化为字符串。 However, most primitives will translate between C# and MongoDB nicely.
但是,大多数原语都会在C#和MongoDB之间很好地转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.