TableAdapter为什么要“插入"?和“选择"自动地? [英] Why does TableAdapter make "insert " and "select" automatically?

查看:82
本文介绍了TableAdapter为什么要“插入"?和“选择"自动地?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在Visual Studio 2010中具有主键,我不确定为什么自动生成器通过TableAdapter配置向导使用插入"和选择"命令使TableAdapter出现.
下面的代码是从向导生成的.

I''m not sure why auto-generator make TableAdapter with ''insert'' and ''select'' command by TableAdapter configuration wizard, if they have any primary keys on VisualStudio2010.

The below code is generated from the wizard.

InsertCommand = INSERT INTO [Table] ([UserID], [Password]) VALUES (@UserID, @Password); SELECT UserID, Password FROM Table WHERE (UserID = @UserID)



我听说如果手动删除选择"块会导致并发冲突异常.

那么可以在DB和TableAdapter之间进行调整吗?

欢迎任何评论.

预先谢谢您.



I heard it caused concurrency violation Exception if ''select'' block is manually removed.

So is it to adjust between DB and TableAdapter?

Any comment is welcome.

Thank you in advance.

推荐答案

TableAdapter类适合那些笨拙的人编写自己的代码.它们在现实世界的代码中几乎没有用,它们破坏了数据抽象的每条规则.编写您自己的数据层.
The TableAdapter classes are for people too dumb to write their own code. They have almost no use in real world code, they break every rule of data abstraction. Write your own data layer.


您好,

特别是当人们向我询问数据交互方案时,我更喜欢SQLHelper类和存储过程.如果您想遵循N层架构,则可以将数据访问层分开.

因此,我建议您为所有数据库交互创建存储过程.如果存储过程中需要,则创建事务.从数据访问层调用您的SP,并将其与真实的Class对象绑定.

说实话,我从未在项目中使用过TableAdapter.

请参考: SQL Helper类 [
Hi,

Specially when people ask me for data Interaction scenario, i prefer SQLHelper class and Stored Procedures. If you would like to follow N-Tier architecture then you can separate you Data Access Layer.

So, i suggest you to create Stored procedure for all your database interactions. Create Transactions if required in the stored procedure. Call your SP from Data Access Layer and Bind it with the real Class object.

Truly speaking i have never used TableAdapter in my projects.

Please refer this : SQL Helper Class[^]

SQL helper class will reduce your work. you can improve that class as per your requirement(but i don''t think you need at this stage)

Thanks
-Amit Gajjar.


这篇关于TableAdapter为什么要“插入"?和“选择"自动地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆