0

I have the following query code for LiteDB that I wrote based upon the website examples:

    private void QueryFunc()
            {
                    using (var db = new LiteDatabase(@"C:\NewTemp\MyData.db"))
                    {
                    var EmployeeCollection = db.GetCollection<Employee>("employeesName");
                    var Finder = EmployeeCollection.Find(x => x.Name_Last.StartsWith("L")).ToList();
                    label_LastName.Text = Finder.ToString();                    
                    }
            }

It operates correctly, however it returns not a string of Last Names, but the object name (System.Collection.Generic.List'[LITEDB.Form1+Employee]). How do I get the 'Find' command to display strings? Also, Is there somewhere that shows the procedure required for the rest of the 'Find' commands (FindOne, FindAll, FindbyId) to display query results in a string format?

Community
  • 1
  • 1
MBasic
  • 23
  • 6
  • Not familiar with LiteDB but, `Finder.FirstOrDefault() ` , and check against possible `null` obviously? – Tigran Aug 25 '17 at 15:33
  • Override the `ToString()` method in the `Finder` class to return what you want. Also, what @Tigran said. – Robert Harvey Aug 25 '17 at 15:34
  • @Tigran, there are no NULLs and yes it does return a string using: label_LastName.Text = Finder.FirstOrDefault().Name_Last; However, that doesn't return the list. – MBasic Aug 25 '17 at 15:43
  • @MBasic: then you can use `Finder.First()` – Tigran Aug 25 '17 at 15:44
  • @Tigran that still seems to return only the first result that matches the parameters and not a list. Is there a way to determine if the list really contains all the results? – MBasic Aug 25 '17 at 15:54
  • @MBasic how do you assign results list to `label` ? – Tigran Aug 25 '17 at 15:57
  • @Robert Harvey in which way are your referring to overriding the string method to return the result from Find class? – MBasic Aug 25 '17 at 16:03
  • The usual way you would override any method. You write `public override string ToString() { // return the desired result }` – Robert Harvey Aug 25 '17 at 16:04
  • @Tigran let me try or use a listbox for testing... – MBasic Aug 25 '17 at 16:16
  • @Robert Harvey I don't know what I'm doing with that way. I wrote an override, but it yielded the same result of one name out of the entire list. It works, but I'm not sure if I'm implementing the code correctly. I basically took the original code from the method QueryFunc and put it into the string override and added 'return newString' so it pretty much acted like a nested method. Was that what you meant? – MBasic Aug 25 '17 at 16:34

0 Answers0