在 .Net Core 中将对象转换为 DocumentDb 文档

convert object to DocumentDb Document in .Net Core

我有以下代码,它根据模型接受一个员工类型的对象,我想将其转换为 DocumentDB 文档,然后 post 到数据库。 我将如何进行转换?

[HttpPost]
        public async Task Post([FromBody]Employee employee)
        {
            using (_logger.BeginScope("Post employee"))
            {
                try
                {
                    // convert employee to Document??
                    await _documentDbRepository.CreateItemsAsync(document);
                }
                catch (Exception e)
                {
                    _logger.LogError(e.Message);
                    throw;
                }

            }
        }

您似乎在常规 Cosmos 库之上使用自定义层,该库被硬编码为仅接受 Document。 Microsoft 提供的库能够插入任何通用对象,并将使用默认 JSON 序列化在插入时将其转换为文档。将自定义存储库上的签名更改为接受 Object 而不是 Document 应该可以让你畅通无阻。