Data Object不应该返回DataView [英] Data Object should nt return DataView

查看:70
本文介绍了Data Object不应该返回DataView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了体现我的数据库,业务逻辑和GUI,我试图让我的数据对象拥有数据库好东西。
所以,对于

的例子,我的GUI应用程序希望得到一个用户列表,将它放在一个组合

框中。它打了一个电话,''GetListOfUsers''。 Business层有一个

函数,它将返回< List>。它调用数据对象

执行SQL。这可能会调用''GetUserList''。当前的数据对象是
,返回一个DataView,这很糟糕,因为我的业务层

然后需要iclude System.Data ...


如何在不使用

数据类的某些fr的情况下从数据对象返回数据?

In an attempt to sparate my database, business logic and GUI, I am
trying to have only my Data Object having database goodies. So, for
example, my GUI app wants to get a list of users to put ito a combo
box. It makes a call, ''GetListOfUsers''. The Business layer has a
function that would return a <List>. It calls the data object which
does the SQL. This would maybe call ''GetUserList''. The data object at
the moment, returns a DataView, Tht''s bad, because my Business Layer
then needs to iclude System.Data...

How can I rather return the data from the Data Object, without using
some fr of data class??

推荐答案

好吧,如果你不想使用System.Data,那么显而易见的选择

将使用自定义类来表示你的数据(而不是

DataTable),但我不确定我是否会考虑使用System.Data

撤消...它将会在任何标准安装的GAC

等。实际上,我最大的抱怨是一个视图(在你的情况下,
中的DataView)并不是一个真正的自我支持实体。我倾向于

返回模型本身(DataTable或DataSet(可能是键入的),或者

[更好的IMO]一组SomeBespokeClass实例(可能是list,array

或集合))。


尽管IMO,DataTable总是固有地过于接近我喜欢的数据库布局。我有点喜欢使用定制课程;

部分是因为这个原因,但也有很多其他人。当这个时候,DLinq会引起人们的兴趣......但我担心的是,这个默认实现再次将过多的数据库知识放入

实体(通过属性)。


Marc
Well, if you don''t want to use System.Data then the obvious choice
would be to use custom classes to represent your data (instead of
DataTable), but I''m not sure that I''d consider using System.Data an
undoing... it is going to be in the GAC of any standard installation
etc. Actually, my biggest gripe here would be that a view (DataView in
your case) isn''t really a self-supporting entity. I would tend to
return the model itself (DataTable or DataSet (probably typed), or
[better IMO] a set of SomeBespokeClass instances (perhaps list, array
or collection)).

Although IMO, DataTable will always inherently be too close to the
database layout for my liking; I''m a bit fan of using bespoke classes;
partly for this reason, but for lots of others too. When

DLinq will be of obvious interest here... but my worry here is that
the default implementation again puts too much database knowledge into
the entities (via the attributes).

Marc


5月8日上午7:50, Marc Gravell < marc.grav ... @ gmail.comwrote:


< snip>
On May 8, 7:50 am, "Marc Gravell" <marc.grav...@gmail.comwrote:

<snip>

DLinq将是显而易见的感兴趣的是......但我担心的是,

默认实现再次将过多的数据库知识放入

实体(通过属性)。
DLinq will be of obvious interest here... but my worry here is that
the default implementation again puts too much database knowledge into
the entities (via the attributes).



我相信有些方法可以在不使用

属性的情况下配置实体,而是使用XML配置文件。


就个人而言,使用其他具有相同选项的ORM系统,

我总是发现使用属性的简单性超过了

优雅的数据库分离使用配置文件。

问的问题是在哪种情况下你真的需要这种脱钩程度,

以及它们出现的可能性。


Jon

I believe there will be ways of configuring the entities without using
attributes, but using an XML configuration file instead.

Personally, using other ORM systems with the same sort of options,
I''ve always found that the simplicity of using attributes outweighs
the elegant database separation of using config files. The question to
ask is in which situations you really need that level of decoupling,
and how likely they are to crop up.

Jon


THanks Marc。对不起,你是什么意思的定制课程。 (抱歉我的

无知在这里)。另外,由于这是我涉及更多分层的

设计,而不是GUI层中的所有内容,

GAC是什么意思?你是说在你的业务层中拥有System.Data是可以的吗?

那个带有''User''类,然后''Account''类等?然后

允许Data对象返回DataSet并不是件坏事吗?如果是这样的话,

如果这是接受的做法,那么......太棒了!我走了。

THanks Marc. Sorry, what do you mean by a bespoke class. (Sorry fot my
ignorance here). Also, as this is me dabbling in a more layered
design, as opposed to everything in the GUI layer, what is meant by
GAC? Are yo saying it''s OK to have System.Data in your business layer?
The one with the ''User'' Class, then ''Account'' class etc? And then
allowing the Data objects to return DataSets isn''t a bad thing? If so,
and if this accepted practise, then.. great! Away I go.


这篇关于Data Object不应该返回DataView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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