I want to enforce the first parameter to be placed on a new line if there are several parameters and not all of them are placed on a single line
this is the setting for that: csharp_wrap_after_invocation_lpar = true
now in a case when there is a single parameter but it spans multiple lines e.g. a ternary expression or a lambda, I prefer it to start on the same line
.Select(r => r.Id == Id.None
? new Unload()
: new Load(r.Id));
instead of
.Select(
r => r.Id == Id.None
? new Unload()
: new Load(r.Id));
is there a way to achieve this?
I played around and was not able to find a setting for your desired behavior. Therefore I'd say it's not possible. But of course, you can ask JetBrains support.
Related
I am trying to check the equality on two strings using the EF Functions like a method, but it is failing somehow and getting null on spaces.
The two strings are like as below, Here you can observe the only difference is the case for SPACE
the displayName is L1-008-5 SPACE and I have stored Displayname in space identity object as like this L1-008-5 Space
L1-008-5 SPACE and L1-008-5 Space
Here is the code
var space = dbContext.Spaces.SingleOrDefault(a => EF.Functions.Like(a.SpaceIdentity.DisplayName, displayName));
and I tried the below options as well
dbContext.Spaces.SingleOrDefault(s => s.SpaceIdentity.DisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase));
dbContext.Spaces.SingleOrDefault(s => string.Equals(s.SpaceIdentity.DisplayName,displayName, StringComparison.OrdinalIgnoreCase));
None of the above are working and getting null on spaces.
Could anyone please point me in the right direction where I am doing wrong with the above comparison.
Many thanks in advance!
Assuming you are using the Npgsql.EntityFrameworkCore.PostgreSQL provider for EF Core, you should have access to the ILike method which is a case-insensitive LIKE. That means you are able to use this code:
var space = dbContext.Spaces
.SingleOrDefault(a =>
EF.Functions.ILike(a.SpaceIdentity.DisplayName, displayName));
// ^^^^^
I want to compare two string values which are not exact For example I want to compare Admin to Administrator, this should return true or should execute.
I tried contain which is not working
var prodcut = lstProducts.Where(i => i.Name.ToLower().Contains(appname.ToLower())).FirstOrDefault();
Above code not working if i.Name is 'Admin' and appname.ToLower() is 'Administrator'. It just return null but want it should detect values.
If you want to check it both ways so if A contains B OR if B contains A you can use the || operator (the OR operator) like so:
a.Contains(b) || b.Contains(a)
You've got the strings the wrong way around (you're looking for Adminstrator in Admin)
You can do the check both ways around like this:
lstProducts.Where(i =>
i.Name.ToLower().Contains(appname.ToLower()) ||
appname.ToLower().Contains(i.Name.ToLower())
).FirstOrDefault();
Or just compare the first few characters:
lstProducts.Where(i =>
i.Name.ToLower().SubString(0,5) == appname.ToLower().SubString(0,5))
).FirstOrDefault();
Fuzzy matching is actually quite a complicated subject but there's a lot of research into the topic.
I want to search a collection based on text box. The user should be allowed to type in multiple words and in any order. Meaning if the string in the collection is "What a happy day" and the user types in "day What" the string should appear. Now I know how to do with with hard coding the number of words allowed (for example only 3 words allowed) with something like this;
nc = oc.Where(X => X.SearchData.IndexOf(words[0]) > -1 || X.SearchData.IndexOf(words[1]) > -1 || X.SearchData.IndexOf(words[2]) > -1);
note: yes I know I would have to protect to make sure there was actual 3 values in the array words but that is not shown.
The problem with this is that it limits the user and I don't want to do that. If the user wants to search off 10 or 20 things then that is fine with me.
Is there a way to dynamically create the Where statement for collection oc?
thanks
You need more LINQ:
oc.Where(x => words.Any(w => x.SearchData.IndexOf(w) > -1))
IndexOf(w) returns true even if w is a matched substring. For instance in your example if user enters Wha then it gets matched with What. As I understand you it is not the case. So you can simply split SearchData and search over it:
var enteredWords = SearchData.Split();
return oc.Where(p=> enteredWords.Any(q=>p.Contains(q));
I think the answer of #Slaks will match on partial words, as per my comment and the answer given by #Alireza
You could try
oc.Where(phrase => phrase.Split().Intersect(SearchData.Split()).Count() > 0);
There are always various ways with LINQ...
I was wondering if there is an easy way to place two Lambda expressions in a single (Linq/Where) query?
For example, I currently call a method with something like the following:
string testing = "blablabla";
if(testing == "" || testing == null)
I have tried a few combinations such as:
testing.Where(x => x == ("") || x=> x == null);
But the above doesn't work. I know I can set up a method that returns a predicate/bool, but, at the moment, I am interested in Lambdas and was just wondering how to achieve this.
Do I need to chain multiple Where methods, or is there a way to achieve multiple Lambdas?
(p.s. I know about IsNullOrEmpty, this is just the first example I could think of!)
You can always combine them to a single lambda.
testing.Where(x => x == null || x == ("") );
If you're looking for a general way to combine query conditions in arbitrary ways, you can use expression trees:
http://msdn.microsoft.com/en-us/library/bb882637.aspx
What would be the right way to sort a list of strings where I want items starting with an underscore '_', to be at the bottom of the list, otherwise everything is alphabetical.
Right now I'm doing something like this,
autoList.OrderBy(a => a.StartsWith("_") ? "ZZZZZZ"+a : a )
If you want custom ordering, but don't want to supply a comparer, you can have it - sql style:
autoList
.OrderBy(a => a.StartsWith("_") ? 2 : 1 )
.ThenBy(a => a);
I think you need to use OrderBy(Func<>, IComparer<>) and specify your own Comparer which will implement your custom logic .
Use the overload of OrderBy that takes an IComparer, the first Func argument will feed the comparer, and from there you need to compare the strings. First deal with the case of one or both starts with _, and then from there you will probably need to strip the _ and just use the standard string.Compare to sort them beyond the first _