C
C#superbobface

❔ Exclude items from linq query if they contain one from an array of substrings

I've got a list of strings, that if they appear anywhere in a linq query column i want to exclude the row. I can find loads of examples of exact matches, or where the column value appears in a list, but not the other way around, and I can't figure it out
S
superbobface398d ago
var providers = from st in context.Providers where st.Practice == dbPractice.FirstOrDefault() && st.Active && !exclusions.Contains(st.Name) select st; this is the reverse, looking to see if st.Name appears in any of the strings in exclusions (List<string>) but i want it the other way around
A
Angius398d ago
What do you mean "the other way around"? Whether a list of exclusions is contained in the name?
S
superbobface398d ago
yea exactly that and then i'll drop those out
A
Angius398d ago
Uh, I can already say that "Thomas" will not contain [ "Bob", "Catherine", "Thomas" ] no matter what you do The list can contain the name The name can't really contain a list
S
superbobface398d ago
quite if the exlucsion list was ["a","e"] then Thomas would be kicked out but Bob wouldn't basically - I probably can't do it in linq? I tried a function whic returns bool, but linq to sql doens't like that of course
A
Angius398d ago
var providers = await _context.Providers
.Where(p => !exclusions.Any(e => s.Name.Contains(e)))
// ...
.ToListAsync();
var providers = await _context.Providers
.Where(p => !exclusions.Any(e => s.Name.Contains(e)))
// ...
.ToListAsync();
Something like this
S
superbobface398d ago
ah okay, I did see an exmaple similar, let me try that
A
Angius398d ago
As a side note, any reason to use Lin12Sql instead of Entity Framework Core?
S
superbobface398d ago
sorry this is EFCore, apologies not linq to sql oh no i'm confused thank you tho
A
Accord397d ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
✅ Comprehension questions (LeetCode Binary Search)Like the title says it's about this puzzle https://leetcode.com/problems/binary-search/description/ ❔ How to create a cubic function calculator that also calculates the minimum and maximum value```c Console.WriteLine("Please enter a, b, c, d for the cubic function ax^3+bx^2+cx+d"); ❔ how to listen to the output of a virtual audio device on windows using C#?how to listen to the output of a virtual audio device on windows using C# to save the raw audio stre❔ How to wait for process to completei want to make program opens async but instead of giving 'hard coded' delays but i don't know how to❔ Problem with including C DLL in a C# console app project.So I have this C DLL imported into my console app (.NET 5). I simply cannot get to call it correctly✅ Win Form Event Handlers questionHi, I was just wondering if there is an event handler when the win form is idle that I can then run ❔ Problem with Dictionary<ulong, Image> (Strange work of memory access)Concept of my system: A system that draws a picture with stickers, each of the stickers can be moved❔ How do I refactor this?I am working with a grid of tiles, each tile has an int, which is made up of 4 bytes which represent❔ [AvaloniaUI] Visibility of item in ListView based on conditionAn Avalonia UI application is used to manage an evidence of items. It allows the user to add items. ✅ How to structure this login/signup page layoutSo I have this mockup of the layout I want for a login/signup page in my Blazor WASM app. Pretty sta❔ I am need of help before I give up and run my code on a server instead of a serverless solution.I have create an azure function locally and i've used the selenuim webdriver package for taking scre✅ .Net Core 6 Asymmetric Encryption with custom public and private keysHello all! How can i use the `Asymmetric Encryption` in .Net 6 but choosing/importing private and pu❔ No Design in C#Instances of this bug (1) 1. View Call Stack at System.Runtime.InteropServices.Marshal.ThrowExce❔ having issues on a reloading script on unity to reload weaponsthe code is used in a youtube video and i have pretty much copied to to get it to work but it doesnt❔ help with an exerciseI've encountered a weird problem that idk how to fix. Say we've got a string "31131123521" how do i ❔ Accessing HTTP Context at DbCommandInterceptor [.NET 7]Hi! I'm having some issues trying to access the HTTP Context at my DbCommand Interceptor class. What❔ XMLAttributeCollection -> Dictionary with LINQ?It's a confusing class. It only allows turning it into a Queryable, but I have no experience with th❔ MS SQL Reporting Server URL Being RedirectedWe have an application from a vendor that was written in C# and we recently upgraded the MS SQL data❔ dataset memory leakI found memory leak and I don't understand how to fix it Test case: ```cpp public class MemoryLeaksT❔ WebAPI .NET 7.0 - Encrypt connectionstring in appsettings.jsonguys, I'm writing some WebAPI using .NET 7.0, and I'd like to secure the connectionstring with encry