Is it possible to return dynamic objects or Dataset from a Sqlite Query?

前端 未结 5 1386
慢半拍i
慢半拍i 2020-12-06 08:39

I am using Sqlite.Net in my Xamarin.Forms application. So far it has been great at returning lists of objects if my object is a class like so:

Sq         


        
5条回答
  •  盖世英雄少女心
    2020-12-06 09:37

    SQLite.NET PCL is a .NET wrapper around sqlite.

    Therefore you can query similar to EF by using a join in in LINQ or Lambda than in the Query. The wrapper will handle the conversion to sqlite query for you.

    You can then return a new datatype of the joined type or a dynamic type.

    Note : Joins are not directly supported in sqlite (more info) and work around is mentioned here.

    Sample code:

    var conn = new SQLiteConnection(sqlitePlatform, "foofoo");
    var query = from customer in conn.Table().ToList()
                join call in conn.Table().ToList()
                             on customer.ID equals call.CustomerId                
                select new { Customer = customer , Calls = call };
    

    Lambda version:

    conn.Table().ToList().Join
    (conn.Table().ToList(),
    customer => customer.Id,
    call => call.CustomerId, 
    (customer, call) => new { Customer = customer, Calls = call });
    

提交回复
热议问题