robertohuertasm / SQLite4Unity3d

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

how to use OrderByDescending #49

Closed demon04551 closed 7 years ago

demon04551 commented 7 years ago

Expression<Func<T, U>>,What is the meaning of this, how to use it

sandolkakos commented 7 years ago

This is an expression that can be used with Lambda. Something like that:

_connection.Table< Person >().OrderByDescending(x => x.Name).FirstOrDefault(); // Get only the first element

_connection.Table< Person >().OrderByDescending(x => x.Name); // Get all elements

demon04551 commented 7 years ago

thank you,How do you know the sorted I want elements in what place

sandolkakos commented 7 years ago

You can store the result in a List or Array, like that: List< Person > personList = _connection.Table< Person >().OrderByDescending(x => x.Name);

Later you can get the index of a specific element, like that: Person person = personList.Where(x => x.Name = "Name").FirstOrDefault(); // you need to import the using System.Linq to use the Where clause. int index = personList.IndexOf(person );

demon04551 commented 7 years ago

How to update existing data,

sandolkakos commented 7 years ago

You need to select the data you want, change the properties and later apply the Update: List< Person > personList = _connection.Table< Person >().OrderByDescending(x => x.Name); Person person = personList.Where(x => x.Name = "Name").FirstOrDefault(); person.Name = "NewName"; _connection.Update(person);