使用linq

时间:2015-09-11 06:14:24

标签: c# .net

我有一个模型结构如下图所示。

 public class GuideLineSectionsViewModel 
    {

        public GuideLineSectionsViewModel()
        {
            SectionsSet = new List<SectionViewModel>();
        }
         public string Title { get; set; }
        public List<SectionViewModel> SectionsSet { get; set; }
    }



    public class SectionViewModel
    {

        public SectionViewModel()
        {
            SectionsSet = new List<SectionViewModel>();
            QuestionsSet = new List<QuestionViewModel>();
            ProblemsSet = new List<ProblemViewModel>();
            GoalsSet = new List<GoalViewModel>();
            BarriersSet = new List<BarriersViewModel>();
            QuestionReferencesSet = new List<QuestionReferenceViewModel>();
        }

        public string Heading { get; set; }
        public List<SectionViewModel> SectionsSet { get; set; }
        public List<QuestionViewModel> QuestionsSet { get; set; }
        public List<ProblemViewModel> ProblemsSet { get; set; }
        public List<GoalViewModel> GoalsSet { get; set; }
        public List<BarriersViewModel> BarriersSet { get; set; }
        public List<QuestionReferenceViewModel> QuestionReferencesSet { get; set; }
    }



    public class ProblemViewModel 
    {
        public string Text { get; set; }
        public bool Identified { get; set; }
        public List<GoalViewModel> GoalsSet { get; set; }
        public List<QuestionReferenceViewModel> QuestionReferencesSet { get; set; }
    }

现在根据条件我需要使用linq.Below更新ProblemViewModel的每个列表值是条件

public GuideLineSectionsViewModel FindGuidelineType(GuideLineSectionsViewModel guidelineSectionModel)
            {
                //GuideLineSectionsViewModel result = new GuideLineSectionsViewModel();
                string title = guidelineSectionModel.Title;
                int count = Regex.Matches(title, "Low Intensity").Count;
                if (count > 0)
                {

                }
                return guidelineSectionModel; 
            }

guidelineSectionModel.Title将包含文本为&#34;某些值:低强度&#34;。所以我使用regx来过滤文本。还有其他方法我可以直接检查linq中的条件。并更新模型模型。

我想将ProblemViewModel模型属性值public bool Identified的列表值更新为&#34; true &#34;

目前它只包含 False 值。

请任何人帮我解决问题。

0 个答案:

没有答案