从 Windows 窗体应用程序进行 C# 轻量级数据访问
我有一个简单的 C# 应用程序,需要访问保留两个变量的管理表。
有人可以告诉我与数据库交互以检索和更新表的最快(就开发时间而言)的方法是什么。我不想创建整个数据层只是为了访问单个表?
I have a simple C# Application that requires access to an admin table which persists two variables.
Can someone tell me what is the fastest(in terms of dev time) method to interact with the database to retrieve and update the table. I don't wish to create an entire data layer just to gain access to a single table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
普通的旧 ADO.NET 应该没问题:
Plain old ADO.NET should be fine:
Linq To SQL 是最佳选择。您从数据库中拖放表,生成类,然后您可以访问您的表,就好像它只是程序中的变量一样。我喜欢这个教程: http://www.thereforesystems.com/linq-to- sql-tutorial/ 但还有很多其他的,只是谷歌。
Linq To SQL is the best choice. You drag-and-drop your table from DB, get class generated then you can access your table as if it is just a variable in your program. I liked this tutorial: http://www.thereforesystems.com/linq-to-sql-tutorial/ but there are many others, just google.
您应该使用现有的 ORM(类似)框架之一,例如:
其中大多数(如果不是全部)将允许您指定数据源并只需拖动表即可进行设计将为您创建数据传输对象的表面,以及查询并将它们保留回数据存储的机制。
You should use one of the existing ORM(-like) frameworks out there, such as:
Most (if not all) of these will allow you to specify your data source and simply drag tables to design surfaces at which point your Data Transfer Objects will be created for you, as well as the mechanisms to query and persist them back to the data store.
我会选择 Ado.Net 和存储过程
I'd go with Ado.Net and stored procedures
您使用什么版本的 .NET?如果是 3.5 或更高版本,请使用使用 http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.aspx 命名空间。
What version of .NET do you use? If 3.5 or later, use LINQ2SQL marked up with attributes from the http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.aspx namespace.