我正在尝试使用以下包添加 cosmosdb 文档:https://github.com/Elfocrash/Cosmonautapi控制器是这样的: [HttpPut] public async Task<IHttpActionResult> PutTenant([ModelBinder(typeof(TenantModelBinder))] Tenant tenant) { //var provider = new MultipartMemoryStreamProvider(); //var contentType = ""; //var content = new byte[0]; //await base.Request.Content.ReadAsMultipartAsync(provider); //if (provider.Contents.Count > 0) //{ // contentType = provider.Contents[0].Headers.ContentType.MediaType; // content = await provider.Contents[0].ReadAsByteArrayAsync(); //} CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStorageKey"].ToString()); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference(ConfigurationManager.AppSettings["certificatesContainer"].ToString()); // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob"); // Create or overwrite the "myblob" blob with contents from a local file. //blockBlob.Properties.ContentType = tenant.ContentType; MemoryStream stream = new MemoryStream(tenant.CertificateFile); blockBlob.UploadFromStream(stream); var tenantStore = CosmosStoreFactory.CreateForEntity<Tenant>(); tenant.CertificatePath = blockBlob.Uri; if (!ModelState.IsValid) { return BadRequest(ModelState); } var added = await tenantStore.AddAsync(tenant); return StatusCode(HttpStatusCode.NoContent); }但是我收到这个错误:Unable to resolve iD for entity of type Tenant
1 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
正如 Github 自述页面在限制部分所述
由于 Cosmosdb 内部 id 属性的工作方式,有一个强制性限制。如果没有字符串,则不能拥有名为 Id 的属性或具有属性 [JsonProperty("id")] 的属性。宇宙 ID 需要以某种方式存在于您的实体模型中。因此,如果它不是实体的一部分,您可以只实现 ICosmosEntity 接口或扩展 CosmosEntity 类。
在您的情况下,推荐的修复方法是TenantId
用[JsonProperty("id")]
属性装饰。
- 1 回答
- 0 关注
- 204 浏览
添加回答
举报
0/150
提交
取消