Telerik UI for Windows 8 XAML

Read operations can be implemented with SQL queries or LINQ to SQLite expressions. In case of LINQ to SQLite, two syntactic forms for specifying queries can be used: query syntax and method syntax. Here are described the methods that implement the reading operations from the database.

  • Synchronous execution of a SQL query with parameters according to the SQLite SQL syntax.

    C# Copy imageCopy
    public List<PersistentType> Get<PersistentType>(string queryStatement, params object[] queryParameter)
  • Asynchronous execution of SQL query.

    C# Copy imageCopy
    public async Task<List<PersistentType>> GetAsync<PersistentType>(string query)
  • Synchronous execution of SQL query resulted to scalar value.

    C# Copy imageCopy
    public ScalarType GetScalar<ScalarType>(string query)
  • Asynchronous execution of SQL query resulted to scalar value.

    C# Copy imageCopy
    public async Task<ScalarType> GetScalarAsync<ScalarType>(string query)
  • Get all the persisted data from the database via LINQ to SQLite provider. This is the base method for switching to LINQ to SQLite use.

    C# Copy imageCopy
    public IQueryable<PersistentType> GetAll<PersistentType>()

Examples: All examples use the database created in the Getting Started section.

  • With SQL query:

    C# Copy imageCopy
    context.Get<Cars>("Select * from Cars");                        // gets all records from Cars table
    context.Get<Cars>("Select * from Cars where OwnerFK = 1");      // gets Carss for owner with ID=1
    context.Get<Cars>("Select * from Cars where OwnerFK = @p1", 1); // gets cars for owner with ID=1 using parameterized query
    C# Copy imageCopy
    context.GetAsync<Cars>("Select * from Cars where OwnerFK = 1"); // gets asynchronously Cars for owner with ID=1
  • LINQ to SQLite - the GetAll method is essential for usage of LINQ to SQLite provider.

    • With query syntax:

      C# Copy imageCopy
      var t1 = from item in context.GetAll<Cars>()
               select item;
      var t2 = from item in context.GetAll<Cars>()
               where item.OwnerFK == 1
               select item;
    • With method syntax:

      C# Copy imageCopy
      var f1 = context.GetAll<Cars>();
      var f2 = context.GetAll<Cars>().Where<Cars>(car => car.OwnerFK == 1);
      var f3 = context.GetAll<Cars>().Where<Cars>(car=>car.OwnerFK==1).OrderBy(car=>car.CarID);
  • Join operations with LINQ:


    The names of the fields should be identical as the names of the records from the result of the join operations.

    • With anonymous type for read only operations using d object:

      C# Copy imageCopy
      var d = from car in context.GetAll<Cars>()
              join owner in context.GetAll<CarOwners>()
              on car.OwnerFK equals owner.OwnerID
              select new { owner.Name, owner.Age, car.Model, car.YearOfModel };
    • With custom entity class for resulted set of fields using SQL query:

      C# Copy imageCopy
      string query = @"select owner.Name as OwnerName,
                              car.Model ,
                              car.YearOfModel ,
                              car.RegistrationNumber ,
                       from Cars as car
                       join CarOwners as owner
                       on car.OwnerFK = owner.OwnerID";
      var queryResult = context.Get<CarCustomInfo>(query);


      C# Copy imageCopy
      public class CarCustomInfo
          public long CarID { get; set; }
          public string Model {get; set;}
          public DateTime YearOfModel { get; set; }
          public string RegistrationNumber { get; set; }
          public string OwnerName { get; set; }
          public int OwnerAge { get; set; }

See Also