2

I am working on Xamarin multi-platform native mobile app. I am using sqlite.net plugin for the database.

Sqlite.Net Plugin

I've created three tables:

public class OrderT
{
    SQLiteConnection database;

    [PrimaryKey, AutoIncrement]
    public int id { get; set; }
    public int client_id { get; set; }
    public DateTime order_date { get; set; }
}

public class OrderDetailT
{
    SQLiteConnection database;

    [PrimaryKey, AutoIncrement]
    public int id { get; set; }
    public int order_id { get; set; }
    public int quantity { get; set; }
    public float price { get; set; }
}

public class ClientT
{
    SQLiteConnection database;

    [PrimaryKey, AutoIncrement]
    public int id { get; set; }
    public string client_name { get; set; }
}

How can I run a query like this in Xamarin Sqlite? Since there is no concept of relationships and foreign key in Xamarin Sqlite.

SELECT OrderT.*, OrderDetailT.*, ClientT.*
FROM OrderT, OrderDetailT, ClientT
WHERE OrderT.client_id = ClientT.id AND OrderT.id = OrderDetailT.order_id

1 Answer 1

2

How can I run a query like this in Xamarin Sqlite? Since there is no concept of relationships and foreign key in Xamarin Sqlite

You can use LinQ to achieve that.

Example:

var list = from orderT in db.Table<OrderT>()
                  from clientT in db.Table<ClientT>()
                  from orderDetailT in db.Table<OrderDetailT>()
                  where orderT.client_id == clientT.id
                  where orderT.id == orderDetailT.order_id
                  select new { client_name=clientT.client_name, client_id = orderT.client_id, order_id = orderDetailT.order_id,price=orderDetailT.price, quality=orderDetailT.quantity };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.