0

I have an ASP.NET MVC 5 application with Entity Framework 6, I'm using the code first approach.

My model is defined as following :

public class EntityBase 
{
   [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
   public int Id {get; set; }
}

public class Question : EntityBase
{
    public QuestionTypeEnum QuestionType {get; set; } 
}

public enum QuestionTypeEnum
{
    none = 0,
    Type1 = 1,
    Type2 = 2
    .
    .
}

public class Answer : EntityBase
{
      public Question Answers {get; set; }
      public userInfo userInfo {get; set; } 
      public bool Isvalidated {get; set;}
      public FilterTypeEnum FitlterType
}

public enum FilterTypeEnum 
{
    filter1 = 0,
    filter2 = 1
} 

public class UserInfo : EntityBase
{
      public UserInfoTypeEnum UserInfoType {get; set; }
}

public enum UserInfoTypeEnum 
{
          type1 = 0,
          type2 = 1,
          type3 = 2
} 

public class Company : EntityBase
{
      public List<Answer> Answers {get; set; }
      public userInfo userInfoAdmin {get; set; } 
}

I have some performance issues, and I want convert the following method to a stored procedure:

public List<Answer> FilterCompanyAnswers(FilterTypeEnum filter, List<Answer> companyAnswers)
{
    var answers = companyAnswers.Where(a => ((a.Question.QuestionType != QuestionType.none &&
                                              a.UserInfo != null) &&
                                                  (((a.UserInfo.UserGroup == UserGroupEnum.type1 ||
                                                    (a.UserInfo.UserGroup == UserGroupEnum.type2 && a.IsValidated)) &&
                                                    a.AnswerTypeId == (int)filter &&
                                                   filter == AnswerTypeEnum.filter1) ||
                                                 ((a.UserInfo.UserGroup == UserGroupEnum.type3 ||
                                                   a.UserInfo.UserGroup == UserGroupEnum.type1 ||
                                                   a.UserInfo.UserGroup == UserGroupEnum.type2) &&
                                                   a.FilterTypeEnum  == (int)filter &&
                                                 filter == AnswerTypeEnum.filter2))) ||
                                                 (a.Question.QuestionType == QuestionTypeEnum.none))
                                                 .OrderByDescending(a => a.DateCreate)
                                    .GroupBy(a => a.KeywordId)
                                    .Select(grp => grp.First())
                                    .ToList();

    return answers;
}

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bilel Chaouadi
  • 37
  • 1
  • 1
  • 6
  • 1
    What database are you using, also, what is your reasoning for wanting to use a SP over a view? – AllMadHare Apr 24 '15 at 02:18
  • Does this link help? [http://stackoverflow.com/a/20911004/636942](http://stackoverflow.com/a/20911004/636942) – Brad C Apr 24 '15 at 03:31

0 Answers0