Reputation: 491
i have written a stored procedure which returns me Customer Name in below format
LastName+", "+FirstName
i have assign it to Class of properties like below.
Customer = DbContext.ExecuteStoreQuery<SearchEmployeeCDTO>("exec GetCustomerDetails").AsQueryable().ToList();
now i want to search the lastName like below i have done for Customer companyName
if(CompanyName!=null && LastName==null)
Customer = Customer.Where(c => c.CompName.Contains(CompanyName)).ToList();
please suggest how i can search for the LastName from combination of lastName and FirstName format
thanks,
Upvotes: 0
Views: 1607
Reputation: 718
if you try to check the values which another list contains the same or not then you can use this : (if you retrieve these as different properties of the generic list element)
bool b = your1stList.Exists(c=> c.firstName == your2ndList.firstName ,
c.middleName == your2ndList.middleName ,
c.lastName == your2ndList.lastName)
if ( b == true)
{
MessageBox.Show("You already have this Customer");
}
this is a good way to retrieve all properties without any concatanation activity..Saves you from some headaches in futural queries ;)
In the other hand, if we continue from your query then you need to get the value of lastname + firstName into a string and use String.Split(",") function to put in a string array then if the word lastName+firstname check the array[0] index for the lastname and array[1] for the firstname .
Choose which way you want..
Upvotes: 0
Reputation: 12711
Maybe this?
if(LastName!=null)
Customer = Customer.Where(c => c.CustName.StartsWith(LastName)).ToList();
Upvotes: 1