简体   繁体   English

如何使用C#操纵本地数据库?

[英]How to manipulate local database with c#?

I'm using Visual Studio 2013, and I created a local Database IN VS with a couple tables that I'd like to manipulate, do stuff like insert items into it, or retrieve data, pretty basic. 我使用的是Visual Studio 2013,我创建了一个本地数据库IN VS,其中包含一些我想操作的表,执行一些操作,例如向其中插入项目或检索数据,这非常基本。

What I'd like to know is if there's a way to manipulate it without doing the whole, Connection String and SQL query style approach. 我想知道的是,是否有一种方法可以在不执行整个操作的情况下进行操作,使用Connection String和SQL查询样式方法。 On my Console application, I added the Data as an item, and I now have a bunch of stuff like Context and such as part of the Solution. 在我的控制台应用程序上,我将数据作为一项添加了,现在我有一堆诸如Context之类的东西,例如解决方案的一部分。 Is there an easier way to reference it than using a connection string every time? 有没有比每次使用连接字符串更容易引用它的方法? Can I treat the tables in it like I would a collection? 我可以像对待集合一样对待表格中的表格吗? If anyone could point me in the right direction that would be really helpful. 如果有人能指出正确的方向,那将非常有帮助。

No; 没有; its a database. 它是一个数据库。 SQL is how you talk to them. SQL是您与他们交谈的方式。

The .NET standard for dealing with a database is ADO.NET (which IIRC LINQ to SQL and LINQ to entities still utilize under the hood). 用于处理数据库的.NET标准是ADO.NET(IIRC LINQ to SQL和LINQ to仍然在幕后使用的实体)。

All of these use standard data connector objects, which use the aforementioned connections strings, etc. 所有这些都使用标准数据连接器对象,这些对象使用上述连接字符串等。

Entity Framework abstracts these concepts away (as you have asked) so I would just use that! 实体框架将这些概念抽象化了(如您所问的),所以我就用它! Note that you still need some of the ADO artifacts (like a connection string). 请注意,您仍然需要一些 ADO工件(例如连接字符串)。

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

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