本文介绍了键入的数据集与业务对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试决定使用类型化数据集或商业 对象是否更好,所以我很感激来自有更多 经验的人的任何想法。 例如,当我使用业务对象填充gridview时,我通过datareader循环 ,使用自定义实例填充数组列表 中间层的类,然后将数组列表发送到 表示层并将gridview绑定到它。 如果我使用类型化数据集,我只需用数据适配器填充它然后将它绑定到gridview。 看起来类似于数据集会更有效率,因为我不会b / b 必须循环通过任何东西。但是类型化的数据集正在恶化,因为它似乎必须在数据访问中一直定义它们才能在n层解决方案中访问层。它们使我的解决方案变得混乱。 业务对象看起来更整洁,看起来更专业,但它们是否有效,并且需要所有循环? 谢谢 比尔 解决方案 那么为什么你不能只使用一个访问DAL对象的业务对象 带回来数据集并将其绑定到网格的数据源? 没有什么能阻止你做这件事。 UI或表示层不应该直接访问数据库。 没有什么能阻止你制作访问 $的DAL对象b $ b数据库表,填充数据集并通过业务层将数据集一直返回到UI,并将数据集绑定到控件。 事实上,UI应该完全没有意识到业务对象层的业务 对象(松散耦合)UI,这是用b / b完成的与 业务层对象交互的表示层接口。您可以发送或发送数据集, arraylist,strings,List,int等内容。很长或者通过 表现层的界面。 我在说什么? MODEL -VIEW-PRESENTER http://www.polymorphicpodcast.com/ 点击''显示'' 点击''Design Patterns Bootcamp:Model View * Patterns * 查看部件1-5 但是对于您目前关注的示例,只需从中恢复 数据集DAL到BUS并将数据集绑定到控件。 Busobject bo = new Busobject(); datagrid1,Datasource = bo .GetDataset(); // DAL将数据集返回到总线,并且BUS返回数据集将数据集绑定到控件。 我确定幕后数据集无论如何都要循环通过....除了 这就是电脑做什么,它们循环......我不会为此担心... 我绝不是大师。因为我只有真正经验丰富的数据集,但是我已经做了很多很多很多阅读,而不是自定义对象。所有 我的研究几乎可以通过以下方式得到满足;数据集对于小型项目来说非常好,但是大型和/或复杂的项目他们只需要b $ b b b b b b b .... .... ... ... .... ... ... ... ... ...定制 对象。 我目前的项目基于数据集及其在某些方面的常规,但 后来在赛道上变成了一个真正的痛苦。 我为获取数据集而做的工作量太多了。 ...每次数据库 更改时,拖拽并将内容放到xsd上.... ugg ...所以即时尝试生成它们并不是一件容易的事......我是/> 希望我们已经去了自定义业务对象......但是我还没有去过那里 所以我不能告诉你....但那就是所有事情都指向...... 我也喜欢整洁....它意味着更快更易读的代码...它的价值 很多......数据集绝不是整洁的:( 希望有所帮助 John Sheppard 无论如何,我确定幕后数据集循环遍历....除了 那是什么计算机做,他们循环......我不会为此担心... 我绝不是一个大师。因为我只有真正经验丰富的数据集,但是我已经做了很多很多很多阅读,而不是自定义对象。所有 我的研究几乎可以通过以下方式得到满足;数据集对于小型项目来说非常适合,但是大型和/或复杂的项目他们只需要让你保持优势......所以对于大型项目来说,值得设置 自定义对象。 我目前的项目是基于数据集及其在某些方面的常规, 但它会去后来在赛道上变成了一个真正的痛苦。 我为获取数据集而做的工作量太多了。 ...每次数据库 更改时,拖拽并将内容放到xsd上.... ugg ...所以即时尝试生成它们并不是一件容易的事......我是/> 希望我们已经去了自定义业务对象......但是我还没有去过那里 所以我不能告诉你....但那就是所有事情都指向...... 我也喜欢整洁....这意味着更快更易读的代码...它的价值 很多...数据集绝不是整齐的:( 为什么这个人需要定制业务o在将数据绑定到控件的情况下,在对象的Arraylist中出现?如果数据集仅以前向方式使用,那么简单地将数据集绑定到 控件是一个更清洁,更快速的解决方案。 我想和你谈谈大项目中使用的数据集。我在一个使用内部书面目标代码生成器的客户端站点上工作 指向基于仅使用存储过程的SQL,以及所有内容 是使用DAL中的数据表和数据集生成的。 DAL由 Windows桌面,Windows服务和Web应用程序使用,在大型项目中也使用了 。 数据集只是内存中数据的表示。这就是全部,并且在DAL中使用的数据集与在DAL中使用未使用数据集的自定义对象一样快且可行的解决方案和数据表, 仍然可以自定义使用DAL数据库的DAL代码 引擎。 它'在上面的示例中使用UI中的数据集和数据表是错误的 。应该从UI中提取数据库访问权限,以便 不会遇到您面临或将要面对大型项目的问题。 I''m trying to decide if it is better to use typed datasets or businessobjects, so I would appreciate any thoughts from someone with moreexperience.When I use a business object to populate a gridview, for example, I loopthrough a datareader, populating an array list with instances of a customclass in the middle tier, and then send the array list up to thepresentation layer and bind the gridview to it.If I use a typed dataset, I just fill it with a data adapter and then bindit to the gridview.It seems like the typed dataset would be more efficient, because I don''thave to loop through anything. But typed datasets are aggravating, becauseit seems like they have to be defined all the way down at the data accesslayer to be accessible in a n-tier solution. They clutter up my solution.Business objects seem tidier, and seem more professional, but are they asefficient, with all the looping required?ThanksBill 解决方案So why can''t you just use a Business Object that accesses a DAL object thatbrings back the dataset and bind it to the grid''s data source? There isnothing stopping you from doing that. The UI or Presentation tier should notdirectly access a database.There is nothing stopping you from making a DAL object that access adatabase table , populate a dataset and return that dataset all the way backto the UI through the Business Layer and bind the dataset to the control.As a matter of fact, the UI should totally be unaware of the Businessobjects (loosely coupled) UI with the Business Object layer, which isaccomplished with the Presentation layer interfaces that interact with theBusiness layer objects. You can send down or bring up things like datasets,arraylist, strings, List, int. long or whatever through the interface of thePresentation tier.What am I talking about?MODEL-VIEW-PRESENTER http://www.polymorphicpodcast.com/click ''Shows''click ''Design Patterns Bootcamp: Model View * Patterns*view parts 1-5But for the example you''re presently concerned about, just bring back thedataset from the DAL to the BUS and bind the dataset to the control.Busobject bo = new Busobject();datagrid1,Datasource = bo.GetDataset(); // the DAL returns a dataset tothe BUS and the BUS returns a dataset binds the dataset to the control.Im sure behind the scenes datasets loop through things anyway....besidesthats what computers do, they loop...I wouldnt worry to much about that...I''m by no means a guru. As I have only really experienced datasets, but Ihave done lots and lots and lots of reading on them vs custom objects. Allmy research can pretty much be sumed up with the following ; Datasets areexcellent for small projects but large and/or complicated projects they justkeep you hemmed in....so for big project it''s worth the setup of customobjects.My current project is based on datasets and its groovy in some regards, butits going to become a real pain in the butt later down the track.The amount of work I have done to just get my datasets generated has beentoo much....Draggin and dropping stuff on to xsd every time the DBchanges....ugg...so im trying to generate them and its no easy task.....Iwish we had of gone custom business objects...but then I havent been thereso I cant tell you....but thats where everything points...I like neat also....it means quicker more readable code...its worthalot...datasets are by no means neat :(Hope that helpsJohn SheppardIm sure behind the scenes datasets loop through things anyway....besidesthats what computers do, they loop...I wouldnt worry to much about that...I''m by no means a guru. As I have only really experienced datasets, but Ihave done lots and lots and lots of reading on them vs custom objects. Allmy research can pretty much be sumed up with the following ; Datasets areexcellent for small projects but large and/or complicated projects theyjust keep you hemmed in....so for big project it''s worth the setup ofcustom objects.My current project is based on datasets and its groovy in some regards,but its going to become a real pain in the butt later down the track.The amount of work I have done to just get my datasets generated has beentoo much....Draggin and dropping stuff on to xsd every time the DBchanges....ugg...so im trying to generate them and its no easy task.....Iwish we had of gone custom business objects...but then I havent been thereso I cant tell you....but thats where everything points...I like neat also....it means quicker more readable code...its worthalot...datasets are by no means neat :(Why does this person need a custom business object in an Arraylist ofobjects in the case of binding data to a control? If the dataset is beingused in a forward only manner, then simply binding the dataset to thecontrol is a much cleaner and faster solution.And I beg to differ with you about a dataset being used in big projects. Iworked at a client site that used an in-house written object code generatorthat pointed to SQL based on using stored procedures only, and everythingwas generated using datatables and datasets in the DAL. The DAL was used byWindows Desktop, Windows Service and Web applications, which was also usedin large projects.A dataset is just a representation of data in memory. That''s all it is, anddatasets used in a DAL is just as fast and a viable solution than usingcustom objects at the DAL that are not using datasets and datatables, whichone could still customize the code of the DAL that used the DAL databaseengine.It''s a mistake using datasets and datatables in the UI in your exampleabove. The database access should have been extracted from the UI so thatone doesn''t face the problems that you are facing or will face for largeprojects. 这篇关于键入的数据集与业务对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-22 10:14