p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640

Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 21st, 2008, 11:24 PM
Authorized User
Points: 111, Level: 2
Points: 111, Level: 2 Points: 111, Level: 2 Points: 111, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: Ogden, Utah, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Tremmorkeep Send a message via MSN to Tremmorkeep Send a message via Yahoo to Tremmorkeep
Default The IDataReader....a suggestion.

While this book is really, really great...I've found that there are a couple of things I do differently. the first being that rather than create a custom reader for each provider, I place the following function in the DataAccess.cs class

 protected T GetField<T>(IDataReader Reader, string ColumnName)
        {
            int i = Reader.GetOrdinal(ColumnName);

            if (i == -1 || Reader.IsDBNull(i))
                return default(T);
            else
            {
                if (typeof(T).IsEnum == true)
                {
                    return (T)Enum.ToObject(typeof(T), Reader.GetInt32(i));
                }

                return (T)Reader.GetValue(i);
            }
        }


Then you all it easily from any of your functions...

myObject=new myObject(GetField<int>(reader, "MyID"));


use of generics can be maximized, and get rid of some of the errors you may encounter with casting..

matt...

tremmorkeep@gmail.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old February 22nd, 2008, 06:10 AM
Friend of Wrox
Points: 1,830, Level: 17
Points: 1,830, Level: 17 Points: 1,830, Level: 17 Points: 1,830, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

matt,

i do a similar type thing with the following in DataAccess.cs:

      /// <summary>
      /// Cast DBNull using generics
      /// </summary>
      public static T CastTo<T>(object value)
      {
          return value != DBNull.Value ? (T)value : default(T);
      }

I then in the provider call it as such (in this case the DAL/Provider/SearchProvider.cs):

        protected virtual SearchItemEntity GetSearchItemFromReader(IDataReader reader)
        {
            return new SearchItemEntity(
                DataAccess.CastTo<string>(reader["linkID"]),
                DataAccess.CastTo<string>(reader["descriptiontext"]),
                DataAccess.CastTo<string>(reader["category"]),
                DataAccess.CastTo<string>(reader["title"]),
                DataAccess.CastTo<string>(reader["source"]),
                DataAccess.CastTo<DateTime>(reader["lasteditdate"]));
        }

i 'think' this is a similar use of generics to what you're doing above ;)



jimi

http://www.originaltalent.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old February 22nd, 2008, 07:11 AM
Friend of Wrox
Points: 1,830, Level: 17
Points: 1,830, Level: 17 Points: 1,830, Level: 17 Points: 1,830, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

matt,

similarly, i use delegates in the BLL/Articles/Articles.cs (and all BLL/*.* classes where appropriate). having read up on it, it's supposedly more efficient and more performant:

        /// <summary>
        /// Returns a list of Article objects filled with the data taken from the input list of ArticleDetails
        /// </summary>
        private static List<Article> GetArticleListFromArticleDetailsList(List<ArticleD etails> recordset)
        {
            List<Article> articles = new List<Article>();
            recordset.ForEach(delegate(ArticleDetails record)
            {
                articles.Add(GetArticleFromArticleDetails(record)) ;
            });
            return articles;
        }

can't say i've got that much data yet to be able to compare, but i've convinced myself :D

jimi

http://www.originaltalent.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old February 22nd, 2008, 11:37 AM
Authorized User
Points: 111, Level: 2
Points: 111, Level: 2 Points: 111, Level: 2 Points: 111, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: Ogden, Utah, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Tremmorkeep Send a message via MSN to Tremmorkeep Send a message via Yahoo to Tremmorkeep
Default

They are quite efficient. Yours does basically the same thing as mine, though I"m storing the Int32 value of some enums in the database, so I had to accomodate converting that back into my enum for use in code...all I do is pass in the enum type when I call GetField.


GetField<EnumCategories>(reader, "CategoryType")

and it returns the proper enum for the code...I like what you did though, fast and efficient.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two question for suggestion? ssomchai BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 April 30th, 2008 10:31 PM
Getting ahead of IDataReader? technimedia BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 July 31st, 2007 12:34 PM
Need your suggestion... popp SQL Language 1 July 2nd, 2007 02:44 AM
Suggestion Snib P2P and Wrox.com Feedback 2 April 10th, 2004 05:27 PM
Suggestion Ben Horne Flash (all versions) 4 April 7th, 2004 10:18 AM



All times are GMT -4. The time now is 11:54 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc