![](/img/trans.png)
[英]What is best way access different database on different engine but with similar structure
[英]What data structure is similar to that of a database?
什么是可以替換像SQL這樣的數據庫的數據結構(如列表,數組等)?
我希望它擁有盡可能多的類似數據庫的功能,比如查詢選擇等等......
如果沒有,建議結構應該是什么樣子
編輯:
我覺得數據表已經足夠好了,謝謝你的答案
如果您要使用實際的SQL數據庫,那么(根據MSDN ):
private static void CreateCommand(string queryString, string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
}
如果您希望不使用實際的SQL數據庫並嘗試直接在代碼中保存數據,關系等(不確定為什么要這樣做),您可以為它創建自己的自定義類。 你想要包含某種形式的表,以及可以查看表的實例等的搜索方法。雖然你需要實現許多功能,所以如果這樣做很難做到您正在嘗試復制真正的SQL數據庫的所有功能。
最簡單的數據結構是F#中的record
或C#中的class
。 這將代表你的桌子。 表的集合將代表數據庫。 您可以使用查詢表達式 (也稱為Linq)進行查詢 ,並按照上面的指示對其進行序列化。 您還可以使用DataTable 。 如果您只是在尋找數據庫的內存表示,那么您可以使用SQLite
。
如果您只想訪問數據庫,可以使用F#中的SQLProvider或F#和C#中的Dapper來實現。
以下是一個包含記錄列表和查詢表達式的示例:
open System
type Row = {
Id: bigint
Name: string
Address: string
}
let table = [
{Id = 100I; Name = "Joe"; Address = "NYC"}
{Id = 101I; Name = "Jane"; Address = "KC"}
{Id = 102I; Name = "Jim"; Address = "LA"}
]
let notInNYC =
query {
for user in table do
where (user.Address <> "NYC")
select user.Name
}
|> Seq.toList
//val notInNYC : string list = ["Jane"; "Jim"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.