我正在开发Xamarin多平台原生移动应用。我正在为数据库使用sqlite.net插件。
我创建了三个表:
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; }
}
如何在Xamarin Sqlite中运行这样的查询?由于Xamarin Sqlite中没有关系和外键的概念。
SELECT OrderT.*, OrderDetailT.*, ClientT.*
FROM OrderT, OrderDetailT, ClientT
WHERE OrderT.client_id = ClientT.id AND OrderT.id = OrderDetailT.order_id
答案 0 :(得分:0)
如何在Xamarin Sqlite中运行这样的查询?由于Xamarin Sqlite中没有关系和外键的概念
您可以使用LinQ来实现这一目标。
示例:
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 };