I need to search a dblinq table so that the function should return the list of rows if any of the fields matches the search input.

It is more similar to google search where you search with any keyword and the list of matching documents are displayed.

I used reflection for this technique. Can you please check if this method is correct or is there any simple method to achieve this?

I have got all the properties of the dblinq table rows and compared if its string type and then checked the value.

**The code I have used**

```
  public static List<Contacts> SearchContact(string searchText)
    {

        List<Contacts> list = new List<Contacts>();
        try
        {
            var rows= from p in context.tblContacts select p;

            foreach (var contact in rows)
            {
                Type type = contact.GetType();
                Type typesearch = searchText.GetType();
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo pro in properties)
                {
                    if (pro.PropertyType == typesearch)
                    {

                        var value = pro.GetValue(contact, null);
                        string val = value as string;

                            if (val != null && val == searchText)
                            {
                                list.Add(contact);
                                break;
                            }

                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
        return list;
    }

```

> 
> PS: I am getting expected output from this method but I would like to know if I have any alternative way too.
> 
> 
>