SQLite4Unity3d icon indicating copy to clipboard operation
SQLite4Unity3d copied to clipboard

Query

Open way2tushar opened this issue 6 years ago • 2 comments

public IEnumerable<Person> GetPersonsNamedRoberto(){ return _connection.Table<Person>().Where(x => x.IName == "Roberto"); } how to implement "Select IName from Person" this query on return line

way2tushar avatar Apr 30 '18 04:04 way2tushar

Hi, I have similar issue, when i use public IEnumerable<Person> GetPersonsNamedRoberto(){ return _connection.Table<Person>().Where(x => x.IName == "Roberto"); } Unity return me a SQLite4Unity3d.TableQuery1[Person]` If you can help me?

sylvainVasseur avatar Jun 04 '18 10:06 sylvainVasseur

The TableQuery class have Select method that apparently using to filter result like in SQL SELECT. But this method not working as intended.

_connection.Table<Person>()
  .Where(x => x.IName == "Roberto")
  .Select(person => person.IName )
 .ToList();

That code should be return List from property IName like in linq. But it my experience, it return [0, 0].

What working for me is get the list, then select it using linq:

using System.Linq;

List<string> names = _connection.Table<Person>()
     .Where(x => x.IName == "Roberto")
     .ToList()
     .Select(person => person.IName )
    .ToList();

That code will return List string of IName. I don't really like it because it's multiple ToList() :(

nirleka avatar Jul 27 '18 15:07 nirleka