robertohuertasm / SQLite4Unity3d

SQLite made easy for Unity3d
MIT License
1.27k stars 265 forks source link

Query #89

Open way2tushar opened 6 years ago

way2tushar commented 6 years ago

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

sylvainVasseur commented 6 years ago

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?

nirleka commented 6 years ago

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() :(