Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 28, 2011 07:18 PM by Mikesdotnetting
Dec 28, 2011 04:25 PM|LINK
I have a conceptual question regarding ASP.net. Please forgive me for placing it in the wrong forum if I have done so. I have a project in which I query multiple databases across multiple systems for data on a single customer and then return said data and
display the data on one screen. Data is retrieved from both Oracle databases [~2 of those] and SQL Server Databases [quite a few more of those] but all data relates to a single customer [based on user input]. A block of data is initially loaded on the Page_Load
event [when not IsPostBack] and the user has the option to load additional data after page load [by expanding one of many collapsed sections on the page] which loads more data. Data from any section comes from multiple databases and very few sections contain
data from just one database.
My question is this: what is the best way to translate this data from the SqlDataReader and OdbcDataReader objects the data is returned in to the web controls. For those sections that contain data from only one database I already use asp:FormView, asp:DataGrid,
and asp:Repeater controls and the .DataBind() method where appropriate. Where data in one section comes from two databases the project currently utilizes the BindingSource BindingCompleteEventHandler to bind data to multiple controls in one section.
As the project grows, these methods are seeming less and less efficient. Is there a simpler way to consolidate data from multiple databases onto a single page. Given an OOP background my first instinct is to create a Customer class and use instances of that
class to store the data and then just access the data using <% ClassInstance.Attribute %> on the aspx page where I want the data to be represented. But this still seems somewhat inefficient.
Can anyone propose a more elegant or efficient solution that I may be missing? Whether it's LINQ, User Controls, Partial Classes I am open to any suggestions. I just can't beat the feeling there must be a better way to do this. I am plenty proficient in
reading MSDN documentation and I have more than enough books on the related subjects so I don't require a tutorial or walkthrough, I would just like to be pointed in the right direction with an explanation of why this would be the best way to accomplish this.
Thank you in advance to anyone willing to venture a solution, you help is greatly appreciated.
Dec 28, 2011 04:33 PM|LINK
Hey Steven, my suggestion would be to continue with your OOP as this will allow you to continue to make your application larger, support multiple data stores and make it easier to maintain. It will also require you to sit down and put some analysis into
it as well prior to coding or refactoring your current project.
If you create a Customer class and have other classes that inherit it you will be able to get the data you need on the presentation layer in a few lines of code vs. pages. Leave all the heavy coding to the data access and business layers. In your presentation
layer you could then take advantage of ObjectDataSources and specify Select, Update, etc methods, which will perform all the work as long as you provide the parameters.
Dec 28, 2011 04:38 PM|LINK
It depends on what problem you are trying to solve.
Binding data directly to web controls from a DataReader is the most performant way to go about things. Popping that data into custom objects and binding instances or collections of those to controls is "better" according to recommended best practice. It
gives strong typing and can make the job of maintaining or extending the application easier. However, it adds a (very) small overhead (transferring data from one container to another).
Incidentally, my preference would be for the OOP approach.
Dec 28, 2011 06:00 PM|LINK
You hit the nail on the head with this one. ObjectDataSource was exactly what I was missing. I completely agree with the benefits of the OOP approach and I was currently in that analysis stage as the project transitioned from the proof of concept phase to
a true application. The missing step in the analysis stage was the translation from data to presentation and the solutions presented here allow an elegant translation from one to the next. I appreciate your quick response time and analysis of the solution.
Thank you very much,
Dec 28, 2011 06:18 PM|LINK
Having been reminded of the ObjectDataSource I would completely agree that OOP is the way to go. Not only can I take advantage of strong typing as you stated but this will make scalability and security much easier.
As a side note, you mention in your reply that recomended best pratice specify the use of objects and binding interfaces. Is there a document perscribing best pratices for ASP.net similar to how http://msdn.microsoft.com/en-us/library/ms731197.aspx specifies
the best pratices for WCF for instance?
Thank you very much for your prompt initial response,
Dec 28, 2011 07:18 PM|LINK
Is there a document perscribing best pratices for ASP.net