简体   繁体   English

C#驱动程序中的MongoDB文档模型代码值类型数据

[英]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.

相关问题 使用 MongoDB C# 驱动程序更新所有文档的字段数据类型 - Update data type of field for all document using MongoDB C# driver 使用C#驱动程序在mongodb中查找计算值最高的文档 - Find document with highest calculated value in mongodb using c# driver MongoDB C#驱动程序:如果不存在则创建文档 - MongoDB C# driver: create document if not exists MongoDB C# 驱动程序 2.0 - 更新文档 - MongoDB C# Driver 2.0 - Update document C#官方MongoDB驱动程序代码,用于更新(替换)MongoDB文档中的内部数组 - C# official MongoDB driver code for updating(replacing) inner array in document in MongoDB 从子文档数组中获取部分模型数组(MongoDB C#Driver) - Get array of partial model from sub document array (MongoDB C# Driver) 使用MongoDB C#驱动程序命令文档字段包含继承的类型对象 - using MongoDB C# Driver order Document Fields with inherited type objects Mongodb C#驱动程序-更新文档,然后选择包含更新文档的集合 - Mongodb C# driver - Update document then select collection with updated document 如何使用MongoDB的官方C#驱动程序检索所有嵌入的文档值? - How to retrieve all embedded document value using the official C# driver for MongoDB? 如何使用 Mongodb c# 驱动程序更新文档的数组字段的特定索引值? - How to update document's array field's specific indexed value using Mongodb c# driver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM