[Solved] LINQ to XML attributes
You can do it this way: var result= xdoc.Descendants(“image”) .Where(x => x.Attribute(“size”).Value == “large”) .Select(x => new User{ Image = x.Value }); Here is Working Example Fiddle solved LINQ to XML attributes
You can do it this way: var result= xdoc.Descendants(“image”) .Where(x => x.Attribute(“size”).Value == “large”) .Select(x => new User{ Image = x.Value }); Here is Working Example Fiddle solved LINQ to XML attributes
Well you must have a foreign key for the parent. Here is an example select * from person parent left join person child on child.Parent_ID = parent.ID where parent.Name like ‘Adam’ I think this should work for you, you could also left join the sub children of the sub children. Or you can write query … Read more
The method db.Personer.Add() expects you to pass in an object of type Personer but you are passing in two strings. You need to create a new Personer object, set any properties you want, then pass that to db.Personer.Add() 1 solved the best overloaded method match for x has some invalid arguments (two more errors)
With data like: public class Data { public String Name { get; set; } public DateTime TimeStamp { get; set; } public Data(String name, DateTime timeStamp) { this.Name = name; this.TimeStamp = timeStamp; } public override string ToString() { return String.Format(“{0} at {1}”, this.Name, this.TimeStamp); } } You can use: var source = new Data[] … Read more
Rather than using ToString, try string.Format. Something like: var query = (from e in Employees let month = e.BirthDate.GetValueOrDefault() let birthmonth = string.Format(“{0:MMMM}”, month) select birthmonth); query.Dump(); This seems to work from my local testing, although it is not included as part of the SQL query. 0 solved Printing Month Name in Linq
In order for {columns}.Concat(rows) to work, it seems you need to add an explicit call to AsEnumerable() in order to make sure the type TSource for Enumerable.Concat(IEnumerable<TSource>, IEnumerable<TSource>) is inferred correctly: Dim csvRows = { columns.AsEnumerable() }.Concat(rows) _ .Select(Function(r) String.Join(“,”, r)) Fixed fiddle #1 here. A DirectCast({columns}, IEnumerable(Of IEnumerable(Of String))) also seems to work, as … Read more
I replaced this: .OrderBy(p => { if (p.Office == “President”) return 0; else if (p.Office == “Vice-President”) return 1; else if (p.Office == “Secretary-Treasurer”) return 2; }).ToListAsync(); with this: .OrderBy(p => p.Office == “President” ? 0 : p.Office == “Vice-President” ? 1 : p.Office == “Secretary-Treasurer” ? 2 : 3).ToListAsync(); I’m hoping it is useful … Read more
You could use: var total = dbo.PrecisionArchive.Where(p => p.AgencySourceId == 7) .Where(p => p.EventType == “R” || p.EventType == “ONS”) .Select(p => p.SampleDateTime) .Distinct() .Count(); 1 solved How to convert SQL query into LINQ?
Simple. Iterate over all strings inside List and then check if myString contains that or not. If yes, then replace it. foreach (string item in lst) { if (myString.Contains(item)) { myString = myString.Replace(item, string.Format(“$${0}$$”, item)); } } Also you can do same with LINQ: lst.Where(item=> myString.Contains(item)).ToList() .ForEach(item => myString = myString.Replace(item, string.Format(“$${0}$$”, item))); You can … Read more
var temp = dbconnect.tblAnswerLists .Where(i => i.StudentNum == studentNumber && i.username==objstu.Return_SupervisorUserName_By_StudentNumber(studentNumber)) .ToList() // <– This will bring the data into memory. .Select(i => new PresentClass.supervisorAnswerQuesttionPres { answerList = Return_Answer_List(studentNumber,i.dateOfAnswer.Value.Date), questionList = Return_Question_List(studentNumber, i.dateOfAnswer.Value.Date), date = ConvertToPersianToShow(i.dateOfAnswer.Value.Date) }) .GroupBy(i => i.date) .OrderByDescending(i => i.Key) .ToList(); temp will actually be of type List<IGrouping<string, PresentClass.supervisorAnswerQuesttionPres>>. 2 solved Group … Read more
Neater, more linq: var data = GetData(); foreach (var v0 in data) { if (v0.Key.Item3 != string.Empty) continue; //Get all related data var tr_line = data[v0.Key]; sb.AppendLine(tr_line.First()); var hhLines = from v1 in data where v1.Key.Item2 == string.Empty && v1.Key.Item1 == v0.Key.Item1 select data[v1.Key]; foreach (var hh_line in hhLines) { sb.AppendLine(hh_line.First()); var grouping = v0; … Read more
Reducing the code to its basic form, your first snippet is of the form list.Where(p => NameContainsPassword(p) || HasEncryptedConfigurationItemAttribute(p)) where I inlined your IsNeverSerializedProperty function. The second function is of the form list .Where(p => NameContainsPassword(p)) .Where(p => HasEncryptedConfigurationItemAttribute(p)) which first filters all items for which NameContainsPassword(p) holds and then from that filters all items … Read more
Create C# classes that map to your json. As below: public class Data { public List<Employee> Employees { get; set; } } public class Employee { public List<EmpDetails> EmpDetailss { get; set; } } public class EmpDetails { public int Empid { get; set; } public string Empname { get; set; } public string Empdept … Read more
As juharr said, use proper classes with properties. But the short and dirty answer would be lists.Where(l => (double)l[1] > 1);, but it assumes that you always have at least two objects in your inner lists and that the second one is always a double. Which is why you should use a strongly-typed object with … Read more
You can pass a comparer to GroupBy, in this case you can use an existing: .GroupBy(x =>x.Function, StringComparer.OrdinalIgnoreCase); 2 solved How to group by ToLower()? [duplicate]