[Solved] How to filter using LINQ? [closed]

Displaying processDate from dataItem2 does not require LINQ… Just user standard dot notation. If this does not answer your question please post the relevant code. Proper way: dataItem2.ProcessDate On the other hand if you have a collection of DataItem objects like below: List<DataItem> items = PopulateMyItems(); then you can filter like so: items.Where(t=>t.ProcessDate > TwoWeeksAgo); … Read more

[Solved] Searching for the newest update in a directory c#

You can use LINQ: int updateInt = 0; var mostRecendUpdate = Directory.EnumerateDirectories(updateDir) .Select(path => new { fullPath = path, directoryName = System.IO.Path.GetFileName(path) // returns f.e. Update15 }) .Where(x => x.directoryName.StartsWith(“Update”)) // precheck .Select(x => new { x.fullPath, x.directoryName, updStr = x.directoryName.Substring(“Update”.Length) // returns f.e. “15” }) .Where(x => int.TryParse(x.updStr, out updateInt)) // int-check and initialization … Read more

[Solved] C# custom add in a List

I would use a HashSet<string> in this case: var files = new HashSet<string> { “file0”, “file1”, “file2”, “file3” }; string originalFile = “file0″; string file = originalFile; int counter = 0; while (!files.Add(file)) { file = $”{originalFile}({++counter})”; } If you have to use a list and the result should also be one, you can still … Read more

[Solved] Prevent duplicates from array, based on condition [closed]

You can write your own extension method that works like the built-in LINQ methods: public static class Extensions { public static IEnumerable<T> DistinctWhere<T>(this IEnumerable<T> input, Func<T,bool> predicate) { HashSet<T> hashset = new HashSet<T>(); foreach(T item in input) { if(!predicate(item)) { yield return item; continue; } if(!hashset.Contains(item)) { hashset.Add(item); yield return item; } } } } … Read more

[Solved] Type of conditional expression cannot be determined because there is no implicit conversion between ‘Entities.KRAParameterInfo’ and ‘string’

Type of conditional expression cannot be determined because there is no implicit conversion between ‘Entities.KRAParameterInfo’ and ‘string’ solved Type of conditional expression cannot be determined because there is no implicit conversion between ‘Entities.KRAParameterInfo’ and ‘string’

[Solved] Why do I get Argument exception when I try to use “Include(“PropertyName”)” in query EF?

I solved the problem. Actually the problem was I didn’t have a using directive to System.Data.Entity namespace at the top of my class. Even thought I could use “Include(“PropertyName)” name in my query, I couldn’t use “Include(x=> x.Childs)”. But after adding “using System.Data.Entity” on top of my class I can use “Include” in these both … Read more

[Solved] SelectMany Linq [closed]

Check the reference source from Microsoft here Following is the SelectMany overload being utilized public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector) { if (source == null) throw Error.ArgumentNull(“source”); if (collectionSelector == null) throw Error.ArgumentNull(“collectionSelector”); if (resultSelector == null) throw Error.ArgumentNull(“resultSelector”); return SelectManyIterator<TSource, TCollection, TResult>(source, collectionSelector, resultSelector); } … Read more

[Solved] Lambda statement for finding sub-string in a string from list of strings [closed]

bool contains = list.Any(yourString.Contains); This is searching for substrings, so it doesn’t compare “words”. Here is a version that ignores the case: bool contains = list.Any(s => yourString.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) >= 0); 2 solved Lambda statement for finding sub-string in a string from list of strings [closed]

[Solved] Convert non-async Linq Extension method to Async [closed]

This is an XY problem. What you’re trying to achieve isn’t the same thing as what your question is asking. Your desired syntax wouldn’t work, even if you made this method async: var courses = await ids.ToChunks(1000) .Select(chunk => Courses.Where(c => chunk.Contains(c.CourseID))) .SelectMany(x => x).ToListAsync(); And the result you really want is just as easily … Read more