且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要MVC帮助

更新时间:2023-08-21 16:10:58

请将您的问题发布到
http://forums.asp.net/1146.aspx/1?MVC
 以便及时回复

Hi,

I would like to build a result like: CategoryID || Count(Searches) || CategoryName based on two Entity Framework based classes:

   

    public class Category
    {
        // Primary properties
        public int Id { get; set; }
        public string  Name { get; set; }
        public string SearchPreviewControllerAction { get; set; }
    }

    public class Search
    {
        // Primary properties
        public int Id { get; set; }
        public string SearchTitle { get; set; }
        public string SearchStandard { get; set; }
        public int CategoryId { get; set; }

        // Navigation properties
        public virtual Category Category { get; set; }
    }

   I already made a SearchPreview method that returns the Searches based on a search like "Aston Martin" that will find in all categories with the words "Aston Martin".

  The challenge now is to build a method that returns, after the Search of the keywords "Aston Martin", in which categories there are those keywords including the count, like "Auto: 2 | Seeling point: 3 | Shop: 2"

  I am trying to avoid a query for each category to count the number of Searches entry, and I would like to find a GroupBy solution, that takes the SearchPreview method already executed and extract the GroupBy Categories that it contains.

  I am using the ViewModel SearchPreviewListCategoriesViewModel to map from the models using Automapper:

    public class SearchPreviewListCategoriesViewModel
    {
        public int CategoryID { get; set; }
        public string Name { get; set; }
        public string SearchPreviewControllerAction { get; set; }
        public int SearchCount { get; set; }
     }

  Hope somoeone can help me on this.

  Thank you.

  Regards,

 Patrick.

Please post your question to http://forums.asp.net/1146.aspx/1?MVC for a prompt response