简体   繁体   English

如何在Visual Studio中配置SQLite数据库?

[英]How to configure SQLite db in Visual Studio?

I've messed with Access a little bit in the past, had one class on OO theory, and one class on console c++ apps. 过去,我对Access有点困惑,在面向对象理论上有一堂课,在控制台c ++应用程序上有一堂课。 Now, as a hobby project, I'm undertaking to write an actual app, which will be a database app using System.Data.SQLite and C#. 现在,作为一个业余项目,我要编写一个实际的应用程序,它将是使用System.Data.SQLite和C#的数据库应用程序。

I have the db's table structure planned. 我已经计划了数据库的表结构。 I have System.Data.SQLite installed and connected to VS Pro. 我安装了System.Data.SQLite并将其连接到VS Pro。 I entered my tables and columns in VS, but that's where I'm stuck. 我在VS中输入了表格和列,但这就是我遇到的问题。 I really don't know how to finish the db set up so I can start creating queries and testing the db structure. 我真的不知道如何完成数据库设置,因此我可以开始创建查询并测试数据库结构。 Can someone give me guidance to online resources that will help me learn how to get the db properly set up so I can proceed with testing it? 有人可以给我在线资源的指导,这将帮助我学习如何正确设置数据库,以便继续进行测试吗?

I'm hoping for online resources specific to beginners using C# and System.Data.SQLite, but I'll use the closest I can get. 我希望使用C#和System.Data.SQLite获得针对初学者的在线资源,但我将使用我能获得的最接近的资源。

Thanks. 谢谢。

Update: Being somewhat comfortable with the notion (and steeled to it also, due to the anticipation of not having a choice), I think I want to use sql-language queries to communicate with the db instead of additional appliances (like ORM's or entity frameworks, etc). 更新:我对这个概念有些适应(由于没有选择的余地,它也被强化了),我想我想使用sql语言查询来与db进行通信,而不是使用其他设备(例如ORM或实体)框架等)。 I would do this to keep my learning curve lower and it seems like I can use what little knowledge I have, since I already don't even know how to proceed configuring the db. 我这样做是为了使学习曲线保持较低状态,并且似乎可以使用我所掌握的很少知识,因为我什至不知道如何继续配置数据库。 So, question 2) Does that sound like a good plan? 因此,问题2)这听起来像是个好计划吗?

What you need now is what is referred to as an Object-Relational Mapper (ORM). 现在,您需要的是所谓的对象关系映射器(ORM)。 This piece of software interfaces your C# objects with your database - enabling you to write queries and updates without working with SQL strings. 该软件将C#对象与数据库连接-使您无需使用SQL字符串即可编写查询和更新。

You can either write a domain-specific ORM for your app, or use one of the millions of off the shelf products. 您可以为您的应用编写特定于域的ORM,也可以使用数百万个现成的产品之一。

Off the shelf ORMs include: 现成的ORM包括:

  • NHibernate - I have never used with Sqlite, but I assume it works NHibernate-我从未使用过Sqlite,但我认为它可以工作
  • sqlite-net - My own little library for working with Sqlite databases. sqlite-net-我自己的小库,用于处理Sqlite数据库。

(There is Microsoft's Entity Framework, but, well, it didn't make the list.) (有Microsoft的Entity Framework,但是,它没有列入清单。)

for what I understood, you are actually trying to browser your database in order to prove that the table structure and the queries you're going to use are sound. 据我了解,您实际上是在尝试浏览数据库,以证明您要使用的表结构和查询是正确的。 Is that correct? 那是对的吗?

If so seems like you're looking for some kind of query interface. 如果是这样,您似乎正在寻找某种查询接口。 I've never used SQLite, but searching for query interfaces, I found this: http://sqlitebrowser.sourceforge.net/ 我从未使用过SQLite,但是在搜索查询接口时,我发现了这一点: http : //sqlitebrowser.sourceforge.net/

It might help. 这可能会有所帮助。

Also look at this question here: Editing SQL query with Visual Studio 2008 还要在这里查看此问题: 使用Visual Studio 2008编辑SQL查询

It might help you to do just what you're looking for. 它可以帮助您完成所需的工作。

Cheers, Wagner. 干杯,瓦格纳。

Since you're just starting off, I suspect it may be easier for you to start with SQL Server Compact . 既然您刚刚开始,我怀疑从SQL Server Compact开始可能会更容易。 It's a zero install, single file database just like SQLite but a lot easier to deal with in a .Net environment in my opinion. 与SQLite一样,它是零安装,单文件数据库,但在我看来,在.Net环境中处理起来要容易得多。

Once you get ADO.Net or Entity Framework running off that, it should be easy to migrate to another database. 一旦使ADO.Net或Entity Framework运行起来,应该很容易迁移到另一个数据库。

EDIT 编辑

For EF configuration please see "Entity Framework(SQL Server Compact)" . 有关EF的配置,请参见“实体框架(SQL Server Compact)”

This will get Entity Framework working off of your SQL Server Compact database file. 这将使Entity Framework脱离SQL Server Compact数据库文件。 From here you simply use LINQ Object Query to manage your data. 在这里,您只需使用LINQ对象查询来管理数据。 Though there are a small set of limitations documented in the above link. 尽管以上链接中记录了一些限制。

The great thing about that is, once you want to support SQL Server Express or SQL Server Standard , or maybe even MySQL in the future, you should only have to modify your connection strings. 这样做的好处是,一旦您希望支持SQL Server ExpressSQL Server Standard ,甚至将来支持MySQL ,您只需要修改连接字符串即可。

You shouldn't have to touch your queries. 您无需触摸查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM