vendredi 12 juin 2015

Create anonymous type list by running sql query in Sqllite database for windows phone

I have to run a sql query in sqllite db and get anonymous result back. I have written the below code.

    var userlist = new List < user_tbl > ();
    var userlogin = new List < user_login_history > ();
    string json = string.Empty;
    using(var dbConn = new SQLiteConnection(DB_PATH)) {
    userlist = dbConn.Query < user_tbl > ("select * from user_tbl");
    userlogin = dbConn.Query < user_login_history > ("select * from user_login_history");
    var listcom = (from n in userlist join ul in userlogin on n.id equals ul.UserID select new {
        n.name, ul.LoginTime
    }).ToList();
    json = JsonConvert.SerializeObject(listcom[listcom.Count - 1]);
}

Now I want to write the join query in sql and get anonymous list of objects back.

I have tried with

var templist = (from n in dbConn.Query<object>("select a.name,
                                               b.LoginTime    
                                               from user_tbl a inner join user_login_history b on a.id=b.UserID")
                select new 
                      { 
                        n.name, 
                        n.LoginTime 
                      }).ToList() 

Which is not executing. Can anybody help me out with this? I am using Sqlite for this.

Aucun commentaire:

Enregistrer un commentaire