簡體   English   中英

如何將查詢結果緩存在類中,然后根據在C#方法中傳遞的參數將其重用於搜索?

[英]How can I cached query result in class and then reuse it for searching based on parameter passed in a Method in C#?

我正在嘗試在ASP.NET MVC Web應用程序中實現搜索屬性功能,該頁面具有“體驗”列表,每種體驗都有一個分配給它的唯一ID並具有一個屬性列表。 當用戶單擊一種體驗時,它將顯示與該體驗相關的屬性。 現在,當用戶單擊另一種體驗時,它將獲得ID並返回公共屬性。 我有一類緩存數據庫結果並存儲它。

public class GetExperienceResponse
{
    public string Experienceid { get; set; }
    public List<string> Properties { get; set; }
   //Example: Expereienceid="E1", Properties="P1,P2,P3" 
              Experienceid="E2",  Properties="P3,P4,P5"
}


public static List<GetExperienceAmenityResponse> GetExperience()
{
//returns experience and related properties here and cached it 
}

我基於單擊的體驗用於搜索屬性的方法是:

public ActionResult ExperienceSearch(string id)
    {
        List<GetExperienceResponse> Experiences  = new List<GetExperienceResponse>();
        Experiences = GetExperience(); //Populate the Experience result list
       //logic for searching. When Click on Experience1, it will pass id "E1" and should display Properties "P1", "P2" and "P3". When Click on both Experience it should display common property which is "P3" here (Intersection of Experience 1 and  Experience 2).
        return View();
    }

實施此搜索的最佳方法是什么? 我可以對返回的結果使用LINQ查詢嗎? 我將不勝感激。 提前非常感謝您!

可以具有用於個人體驗的唯一Cachekey,並且可以具有用於公共屬性的通用緩存鍵(Experienceid1和Experienceid2的哈希鍵)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM