This question is locked. New answers and comments are not allowed.
When the user wants to search, the app is coded to hide buttons and navbars and a blank database record is added to the bindingsource list at the end and the bindingsource is positioned to the end of the list. Hence, this blank record serves as a buffer to collect values for a search routine using the same UI as data entry. Inside the search (after the user has clicked to get results) routine, there is code as follows where _s is said record of type Document:
I tried the following code first because I would like to generalize this idea to any record, not just this Document type:
I know this last snippet needs work, as I have dates to handle. The Where call throws an exception stating that the server does not support "fi.GetValue". I understand that this may be an issue with the Telerik LINQ compiler which seems to pass stuff onto the server if it doesn't understand it. I know there are several ways to skin a cat in LINQ. I would like to skin this cat using Telerik's tools.
Is there a way to do generic search using this Reflection idea?
Regards,
Guy
var r = _xdb.Documents; if (!string.IsNullOrEmpty(_s.Comments)) r = r.Where(d => d.Comments.Contains(_s.Comments));if (!string.IsNullOrEmpty(_s.Electronic_Document)) r = r.Where(d => d.Electronic_Document.Contains(_s.Electronic_Document));if (!string.IsNullOrEmpty(_s.ManfSupplier)) r = r.Where(d => d.ManfSupplier.Contains(_s.ManfSupplier));...I tried the following code first because I would like to generalize this idea to any record, not just this Document type:
foreach (FieldInfo fi in _s.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)){ object v = fi.GetValue(_s); if (v == null) continue; if (fi.FieldType != typeof(int) && fi.FieldType != typeof(string)) continue; if (fi.FieldType == typeof(int) && (int)v == 0) continue; if (fi.FieldType == typeof(string)) { if (string.IsNullOrEmpty(v.ToString())) continue; results = results.Where(d => fi.GetValue(d).ToString().Contains(v.ToString())); } else results = results.Where(d => fi.GetValue(d) == v);}I know this last snippet needs work, as I have dates to handle. The Where call throws an exception stating that the server does not support "fi.GetValue". I understand that this may be an issue with the Telerik LINQ compiler which seems to pass stuff onto the server if it doesn't understand it. I know there are several ways to skin a cat in LINQ. I would like to skin this cat using Telerik's tools.
Is there a way to do generic search using this Reflection idea?
Regards,
Guy