首页 > 解决方案 > LINQ: select specific value in a datatable column

问题描述

In table I have 4 Columns GroupName, Display, Value and ID How can I just show a specific data in display. I only want to show some of the groupNames Data for example I only want to show Groupname = company and display = Forbes

Here's my linq

                sample = (from c in smsDashboardDBContext.CodeDefinitions
                                  orderby c.Display ascending
                                                                    
                                  select new CodeDefinitionDTO

                                  {
                                      GroupName = c.GroupName,
                                      Display = c.Display,
                                      Value = c.Value,
                                      Id = c.Id

                                  }).ToList();

标签: c#linq

解决方案


您可以where在查询中添加语句。

where c.GroupName == "company" && c.Display == "Forbes"

推荐阅读