Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2012, 08:03 PM
Authorized User
 
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default Declare tableadpaters globally on a page or keep them inside event handlers?

I am having a hard time finding an answer to this on the web. If I am using the same Table Adapter in multiple events on a page is it better to just declare it once at the top of the page?

Performance wise, is there a difference?


Thanks.
 
Old June 9th, 2012, 05:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Yes, if they contain the same data, you should declare one outside all your methods and then fill it once. Where you do that depends; can be with a helper method that is called by each event handler, or you can do it in Page_Load or in the first event that fires.

Why are you using TableAdapters? Is that a deliberate design choice? They are more or less considered out-dated in .NET 4 applications....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 10th, 2012, 01:01 PM
Authorized User
 
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

Yes, if they contain the same data, you should declare one outside all your methods and then fill it once. Where you do that depends; can be with a helper method that is called by each event handler, or you can do it in Page_Load or in the first event that fires.

Why are you using TableAdapters? Is that a deliberate design choice? They are more or less considered out-dated in .NET 4 applications....

Cheers,

Imar
Yea, I know TableAdpaters are obsolete but they are just so easy to use that I am using them for this site. Their downfalls are definitely apparent if I make changes to the database schema, that's for sure.

However, I am not proficient at LINQ but my SQL is pretty good so I like how you can just create query methods for each TableAdapter quickly just by using SQL queries. I also like how you can create partial classes of the TableAdapters to add business logic into the methods.

With the Entity Framework, if you want to group queries together with your tables is their any other way to do it other then hand coding classes for each table using LINQ in each method? Basically other then hand coding a the entire DAL yourself?

Not that it's a bad thing, it's just something that is very new to me.

Last edited by IceThatJaw; June 10th, 2012 at 08:43 PM..
 
Old June 11th, 2012, 04:25 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
With the Entity Framework, if you want to group queries together with your tables is their any other way to do it other then hand coding classes for each table using LINQ in each method? Basically other then hand coding a the entire DAL yourself?
Absolutely. You can create queries that JOINs two or more tables or get related entities. Depending on the data you need you then query complete entities or you can use anonymous objects. In the latter case, you can't return them from a method so you either need to create a class that serves as a ViewModel (which simply copies over your data into an object that doesn't do more than just hold data for transport) or return full entities.

If you can describe your scenarios in more detail, I might be able to supply a better answer and code example.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
IceThatJaw (June 11th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
parameters in event handlers ajaxbeginner BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 1 December 3rd, 2009 11:59 PM
Event handlers jwebb Visual Basic 2005 Basics 1 June 25th, 2007 08:44 PM
Event handlers does not work after some changes geetageetageeta ASP.NET 2.0 Basics 0 March 6th, 2006 04:19 AM
Conflicting Event Handlers chp Excel VBA 3 February 24th, 2006 03:00 PM
Dynamically change event handlers oranginalab Javascript How-To 2 July 31st, 2003 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.