|
|
 |
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.
|
 |

February 21st, 2008, 11:24 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Location: Ogden, Utah, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

February 22nd, 2008, 06:10 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
|
|
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
|

February 22nd, 2008, 07:11 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
|
|
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
|

February 22nd, 2008, 11:37 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Location: Ogden, Utah, USA.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
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 |
|
 |