.Net安裝SQLite

來源:互聯網
上載者:User

資料庫冒似國內的遊戲用戶端用得比較少, 我見的都是用excel自己轉換的...

其實一直想在引擎裡加個資料庫, 但是這個跟遊戲邏輯比較緊密, 就沒搞...

不過, 可以確定的是, 脫離伺服器啟動並執行資料庫最好的選擇應該是SQLite

在用.Net做工具時正好要用, 於是查了一下, 找到兩種解決方案:

  • sqlite-net

    • 小巧, 一個cs檔案, 一個native dll(C++也可以調用)
    • 介面清晰, 基本上一看就懂, 好學
    • 支援LINQ, 雖小卻功能一個不少
    • 相當於原生sqlite c api的一個封裝吧
  • System.Data.SQLite
    • 通過ADO.NET的方式訪問
    • 可以與VS的Designer整合, 這樣可以省去一個資料編輯器
    • 對於使用過ADO.NET的人來說, 很快就可以上手
    • 如果以後改用其它資料庫(如MySQL), 可以不改動代碼

把Northwind的資料庫進來做了一個WPF的資料繫結DEMO:

Xhtml代碼
  1. <DockPanel>  
  2.     <ListBox Name="listCategory" ItemsSource="{Binding}" MinWidth="100" SelectedIndex="0">  
  3.         <ListBox.ItemTemplate>  
  4.             <DataTemplate>  
  5.                 <TextBlock Text="{Binding CategoryName}"></TextBlock>  
  6.             </DataTemplate>  
  7.         </ListBox.ItemTemplate>  
  8.     </ListBox>  
  9.     <StackPanel>  
  10.         <TextBox Text="{Binding SelectedItem.CategoryName, ElementName=listCategory}"></TextBox>  
  11.         <TextBox Text="{Binding SelectedItem.Description, ElementName=listCategory}"></TextBox>  
  12.         <Image Source="{Binding SelectedItem.Picture, ElementName=listCategory}"></Image>  
  13.     </StackPanel>  
  14. </DockPanel>  

如果追求功能強大與自動化, 可以選擇後者.

前者的話需要自己去定義表格對應的class, 沒有那麼便利. 但是代碼要簡潔很多:

C-sharp代碼
  1. var db = new SQLiteConnection("Database/Northwind.db3");  
  2. var result = db.Query<Category>("select * from Categories");  
  3. this.DataContext = result;  

對於沒有怎麼接觸過ADO.NET的人來說, 這種直接的操作方式更好懂一些吧

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.