【发布时间】:2026-02-11 02:00:02
【问题描述】:
我的主要对象,有一个属性是标签列表
[SharedCosmosCollection("shared")]
public class GlobalPageTemplate : ISharedCosmosEntity
{
/// <summary>
/// Id
/// </summary>
[JsonProperty("Id")]
public string Id { get; set; }
/// <summary>
/// Cosmos Entity name
/// </summary>
[CosmosPartitionKey]
public string CosmosEntityName { get; set; }
/// <summary>
/// Page name
/// </summary>
public string ExtractedPageName { get; set; }
/// <summary>
/// Site collection Template Name
/// </summary>
public string ExtractedSitecollectionTemplateName { get; set; }
/// <summary>
/// GlobalDesignTenantId
/// </summary>
public string ExtractedGlobalDesignTenantId { get; set; }
/// <summary>
/// Global design tenant site collection url
/// </summary>
public string ExtractedGlobalDesigntenantSiteCollectionUrl { get; set; }
/// <summary>
/// Page template picture Url
/// </summary>
public string PageTemplatePictureUrl { get; set; }
/// <summary>
/// Base64 image of the page template
/// </summary>
public string Base64Image { get; set; }
/// <summary>
/// Name of the template
/// </summary>
public string PageTemplateName { get; set; }
/// <summary>
/// Page sections
/// </summary>
public List<Section> Sections { get; set; }
/// <summary>
/// Tags
/// </summary>
public List<Tag> Tags { get; set; }
}
标签对象在这里:
public class Tag : ISharedCosmosEntity
{
/// <summary>
/// Id
/// </summary>
[JsonProperty("Id")]
public string Id { get; set; }
/// <summary>
/// Tag name
/// </summary>
public string TagName { get; set; }
/// <summary>
/// cosmos entity name
/// </summary>
[CosmosPartitionKey]
public string CosmosEntityName { get; set; }
}
在我的 WebAPI 中,从前端,我可能会得到重复的标签,
如何在保存之前删除它们并留下一个干净的标签列表?
【问题讨论】:
-
你可以考虑写一个
DistinctBy方法:见*.com/questions/489258/…。