Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to use two string values inside a column to get the results and ,i cant use that it shows as " No Overload for method 'Contains' takes 2 arguments "

is there any way to overcome this

What I have tried:

data = data .Where(p => p.fld_type.Contains(type = "Login")).Where(p => p.fld_action.Contains(action = "Login by Mobile Number")).Where(p => p.fld_status_code.Contains(statusCode = "200")).Where(p => p.fld_output_value.Contains(opValue = "Success","OTP has been sent")).ToList();
Posted
Updated 2-Jun-22 18:32pm

You cannot specify a field inside the argument for Contains. We don't know anything about your object strucutre, so it's impossible to be precise, you would be looking for something closer to this:
C#
data = data
    .Where(p => p.fld_type.type.Contains("Login"))
    .Where(p => p.fld_action.action.Contains("Login by Mobile Number"))
    .Where(p => p.fld_status_code.statusCode.Contains("200"))
    .Where(p => p.fld_output_value.opValue == "Success" || p.fld_output_value.opValue == "OTP has been sent"))
    .ToList();

Of course, in order for this to return anything, ALL of those Where clauses would have to evaluate to True.
 
Share this answer
 
Comments
George Swan 3-Jun-22 3:12am    
Would it not be better to have a single Where statement and use the && operator to link the various conditions together? Also, it seems to me, that the Contains method should be replaced by the == operator because Contains 200 would be true for a string that contains 2000. As there are multiple conditions to be tested, it would probably be better for the Data Type to have a bool Verify() method or a bool IsVerified property so that the test would be simply, data.Where(p=>p.IsVerified) . Another suggestion would be to replace, where possible, the magic strings with an enumeration value.
Dave Kreskowiak 3-Jun-22 6:59am    
Yeah, but there's not enough information in the question to determine what he's actually trying to do and on what fields in his data object.

I left it as an exercise for the OP and just showed how the Contains works.
Manojkumar-dll 3-Jun-22 7:39am    
@Dave i tried yours but it showing like "Severity Code Description Project File Line Suppression State
Error CS1061 'string' does not contain a definition for 'opValue' and no accessible extension method 'opValue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?
"
i have passed the opValue Parameter
Dave Kreskowiak 3-Jun-22 7:47am    
As I said in the answer, we don't know anything about your class structure, so you can NOT take that code and paste it into yours and expect it to work.

I showed you how Contains works. Now it's up to you to apply it to your code.
The error is telling you that whatever class Contains is being called on (and we have no idea what type any of the properties of your class you are calling it on are) the definition does not contain a version which takes two parameters.

So start with your class definition and look at the property types for fld_type, fld_action, fld_status_code, and fld_output_value actually are - because if they are strings then that is some very odd looking code indeed, and if they aren't, then you need to look at what overloads each type implements for a Contains method.

Sorry, but we can't do that for you!

And frankly, that looks pretty poor code to start with: Why isn't it one Where call with ANDed conditions instead of four iterators?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900