x.Attribute("id").Value == chartId.To...">

The article in lambda expression

var Charts = chartGroup .Descendants("charts") .Elements("chart") .Where(x => x.Attribute("id").Value == chartId.ToString()) .Select(x => x.Attribute("name").Value).ToList(); 

Here I want to use "in-clause" "(for example, an in clause in SQL) for Attribute("id").Value for an array of strings:

as:

 Where(x => x.Attribute("id").Value in ("1","2") Where(x => x.Attribute("id").Value` in charIds[] 

how to achieve this?

+8
c # lambda linq
source share
7 answers

If you have a set of values โ€‹โ€‹in an array, you can use:

 .Where(x => charids.Contains(x.Attribute("id").Value) 
+20
source share

You can use the Contains IEnumerable method:

 var ids = new[]{"1", "2"}; Where(x=>ids.Contains(x.Attribute("id").Value)); 

update:

In addition, this code will be passed in the 'in' expression in SQL for IQueryable.

+3
source share

You can do something like this:

 var ids = new []{"id1","id2", ... }; var Charts = chartGroup.Descendants("charts") .Elements("chart") .Where(x => ids.Contains(x.Attribute("id").Value)) .Select(x => x.Attribute("name").Value).ToList(); 
+3
source share

IN in LINQ Enumerable.Contains or Enumerable.Any . Here are a few approaches:

 string[] strIDs = new[]{ "6", "7" }; int[] intIDs = new[]{ 1, 2 }; char[] charIds = new[]{ '4', '5' }; .... .Where(x => strIDs.Contains(x.Attribute("id")) || intIDs.Any(i => i.ToString() == x.Attribute("id")) || charIds.Any(c => c.ToString() == x.Attribute("id"))); 
+1
source share

something like ... where is charIds.Contains (x.Attribute "id" .Value)

0
source share

SQL Where โ€“ In functionality can be easily achieved with a lambda expression. SQL query -

 Select Name,Id from Category Where Id In (71,72) 

Lambda expression -

 List checkedRecords = new List { 71, 72 }; var Cs = Context.Categories.Where(c => checkedRecords.Contains(c.Id)); 

Hope this helps.

0
source share
 var memberData = (from u in _objGroupRepositoty.Value.GetUsers() join umedia in _objGroupRepositoty.Value.GetMediaDetails() on u.userid equals umedia.userid join gm in _objGroupRepositoty.Value.GetGroupMaster() on groupId equals gm.GDID join m in _objGroupRepositoty.Value.GetGroupMembers() on u.userid equals m.userid join media in _objGroupRepositoty.Value.GetMediaDetails() on gm.GDID equals media.GDID where (m.GDID == groupId && m.IsActive == true && gm.IsActive == true && u.IsActive == true) select new { userid = u.userid, firstname = u.firstname, lastname = u.lastname, mobile_no = u.mobile_no, imagepath = umedia.media_path, IsAdmin = m.IsAdmin, GroupID = gm.GroupID, group_name = gm.group_name, tagline = gm.tagline, groupImage = media.media_path, ChatRoomId = gm.ChatRoomId, OperationType //newMember = newMemberLists.Contains(u.userid) than "Y" : "N", }).ToList().Distinct(); 
-one
source share

All Articles