Argument Exception [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Building a list from model in C# using Entity Framework. I am using LINQ to try to match up the first 6 or 7 characters in a field. In a language other than C# I would use a regex expression.. or in SQL a "Like" with wildcard symbols. Below is the code I'm using, and I am getting an Argument exception.
List<InvoiceHeader> tempData = db.InvoiceHeader
.Where(f => f.ivh_invoicenumber.Any(t => f.ivh_invoicenumber.StartsWith(temp))).ToList();

If ivh_invoicenumber and temp are of type string
var tempData = db.InvoiceHeader.Where(f => f.ivh_invoicenumber.StartsWith(temp)).ToList();
If temp is array of strings:
var tempData = db.InvoiceHeader
.Where(f => temp.Any(t => f.ivh_invoicenumber.StartsWith(t))).ToList();

Related

I want compare two string and want to get possible matches [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
sb.Qualilfication_Master.First().Qual_List contain string values like "B.C.A,M.C.A,B.B.A"
and txtQualification.text contain string like "B.C.A, M.Com"
I want match above two thing
var sendnoti = (from p in db.Reg_JobSeeker_Masters where p.Qualification_Masters.First().Qual_List.Contains(txtQualification.Text)select p).ToList();
If I'm reading this right - and you want to find the strings that are common to two lists - then you can just use the intersect method.
I am just assuming txtQualification.Text is a List<string> so in that case you could just right it like this -
var sendnoti = (from p in db.Reg_JobSeeker_Masters where p.Qualification_Masters.First().Qual_List.Any(ql => txtQualification.Text.Contains(ql))select p).ToList();

Predicate matching a list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to do something like -
List<int> accountList = new List<int>();
accountList .Add(1);
accountList .Add(27);
var rec = _db.Accounts.Where(a=> accountList.Contains(a.accountId)).Take(10);
My code is a little more complicated than this - there are several other conditions in the where clause, but this is the bit that is causing problems - nothing gets returned even when there are matching values.
Basically I want it to retrieve all the records where accountId matches a value in my list.
Any pointers?
The sample above is giving me a cant convert lambda error.
You are missing a bit on your contains version
var hold2 = _db.Accounts.Where(a => find.Contains(a.accountDd)).Take(10).ToList();
Have you tried using any
var hold2 = _db.Accounts.Where(a => accountList.Any(m => m == a.accountId)).Take(10).ToList();

C# Search JSON file and select node [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
So I have an application that uses the Newtonsoft.Json dll and I need to search a JSON file for a value entered by the user, then select the node with that value in.
JSON Snippet
So the user will search for the 'name' tag and I need to be able to fetch the 'ID' of the node.
Example:
Name: Blimp
-----------------Fetching ID-----------------
ID: 302686
Seeing as the item you want to (actually) search is an array, you'd have to deserialize the JSON into a C# object. Then, you can access the array, on which you can unleash search functions like a LINQ expression:
var item = Array
.Where(x => x.name == given_name)
.Select(x => x.id);
or Lambda:
var index = Array.FindIndex(x => x.name.Equals(given_name));
var item = Array[index];

Find the object which contains an object with a specific property value in a nested list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a generated c# class from a XML file and I need to search in a Class Object. I will find a specified string in a List have a List but I don't know how to do this, I have tryed this but It wont work:
AdrType = HeaderObj.ClientObj.OrgObj.Addresses.First( s => s.AddressTypes.Select( aD => aD._Type_.Where(sX => sX = "a"))).AddressCode
Something like this?
var adressWithTypeA = Addresses
.FirstOrDefault( s => s.AddressTypes.Any(x => x._Type_ == "a"))
if (adressWithTypeA != null)
{
var adressCode = adressWithTypeA.AddressCode;
}

How convert a row in csv to array of double? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have the following data:
1,1,1,1,1,1
I want to read that line and covert it into array of ints or some other type.
Is there a one line solution to do that?
var arr = "1,1,1,1,1,1".Split(',').Select(s => int.Parse(s)).ToArray();
In case your text includes some spaces
var arr = Regex.Matches("1,1,1,1,1,1", #"\d+")
.Cast<Match>()
.Select(m => m.Value)
.ToArray();

Categories