瀏覽代碼

修改T的注解内容

CrazyIter 5 年之前
父節點
當前提交
a75ffc107d
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs

+ 12 - 2
TEAMModelOS.SDK/Module/AzureCosmosDB/Implements/AzureCosmosDBRepository.cs

@@ -144,9 +144,19 @@ namespace TEAMModelOS.SDK.Module.AzureCosmosDB.Implements
 
         private async Task<DocumentCollection> InitializeCollection<T>()
         {
-            Type t = typeof(T);
+            Type type = typeof(T);
             string partitionKey = GetPartitionKey<T>();
-            return await InitializeCollection(t.Name, partitionKey);
+            string CollectionName;
+            IEnumerable<CosmosDBAttribute> attributes = type.GetCustomAttributes<CosmosDBAttribute>(true);
+            if (!string.IsNullOrEmpty(attributes.First<CosmosDBAttribute>().Name))
+            {
+                CollectionName = attributes.First<CosmosDBAttribute>().Name;
+            }
+            else
+            {
+                CollectionName = type.Name;
+            }
+            return await InitializeCollection(CollectionName, partitionKey);
         }
 
         private async Task<DocumentCollection> InitializeCollection(string CollectionName, string PartitionKey)