Posted by pieterg on 3/9/2010 7:37 AM | Comments (44)

So, I recently had the chance to quickly write some code that gave me the ability to quickly get data from the database.

I didn’t like the naming of the columns so I came up with an Attribute ColumnMapping that has UIName and DBName properties and here is the method to retrieve the data

/// Context Mapper that takes an Attribute and maps it from the stored procedure
///
///
public static class ContextMapper<T> where T : new()
{
    private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    ///
    /// Get Data Maps the data from a Stored Procedure result to a Type
    ///
    ///
    ///
    public static List GetData(StoredProcedure storedProcedure)
    {
        List results = new List();
        DbDataReader dbReader = storedProcedure.ExecuteReader();

        while (dbReader.Read())
        {
            T result = new T();
            PropertyInfo[] propertyInfos = typeof(T).GetProperties();
            foreach (PropertyInfo propInfo in propertyInfos)
            {
                int? ordinal = null;
                try
                {
                    ordinal = dbReader.GetOrdinal((propInfo.GetCustomAttributes(typeof(ColumnMapping), false)[0] as ColumnMapping).ColumnName);
                }
                catch (IndexOutOfRangeException ex)
                {
                    //Couldn't find ordinal, probably doesn't exist in the collection
                    logger.Warn(ex.Message, ex);
                }
                if (ordinal != null)
                {
                    if (propInfo.GetCustomAttributes(typeof(ColumnMapping), false).Count() && !dbReader.IsDBNull(dbReader.GetOrdinal((propInfo.GetCustomAttributes(typeof(ColumnMapping), false)[0] as ColumnMapping).ColumnName)))
                    {
                        propInfo.SetValue(result, dbReader[(propInfo.GetCustomAttributes(typeof(ColumnMapping), false)[0] as ColumnMapping).ColumnName], null);
                    }
                }
            }
            results.Add(result);
        }
        return results;
    }
}

Comments

guitar lessons for beginners
guitar lessons for beginners United States on 3/11/2010 3:08 PM i know this is not exactly on topic, but i run a blog using the blogengine platform as well and i'm having issues with my comments displaying. is there a setting i am forgetting? maybe you could help me out? thanx.
Used Computers
Used Computers Canada on 3/13/2010 1:22 AM Aw, this was a really quality post. In theory I'd like to write like this also - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get anything done... Regards… http://www.pctechoutlet.com
learn to play the guitar
learn to play the guitar United States on 3/13/2010 11:12 AM i know this is not exactly on topic, but i have a blog using the blogengine platform as well and i'm having problems with my comments displaying. is there a setting i am missing? maybe you could help me out? thanks.
Luigi Fulk
Luigi Fulk United States on 3/14/2010 8:10 AM I really enjoyed browsingyour blog. I will be back
Colon Cleansing
Colon Cleansing United States on 3/14/2010 9:19 AM Thanks for the read. I very much like your blog and will be back! Thanks.
Free Apple Ipad
Free Apple Ipad United States on 3/19/2010 8:44 PM Great Read. I will Be back soon.
wow leveling guide
wow leveling guide United States on 3/21/2010 10:40 PM Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.
current health events
current health events United States on 3/30/2010 4:51 AM Between me and my husband we've owned more MP3 players over the years than I can count, including Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few years I've settled down to one line of players. Why? Because I was happy to discover how well-designed and fun to use the underappreciated (and widely mocked) Zunes are.
fat loss 4 idiots review
fat loss 4 idiots review United States on 3/31/2010 2:46 PM if i upgrade my blog, is it going to keep my same settings?
fibroids surgery
fibroids surgery United States on 3/31/2010 5:57 PM Zune and iPod: Most people compare the Zune to the Touch, but after seeing how slim and surprisingly small and light it is, I consider it to be a rather unique hybrid that combines qualities of both the Touch and the Nano. It's very colorful and lovely OLED screen is slightly smaller than the touch screen, but the player itself feels quite a bit smaller and lighter. It weighs about 2/3 as much, and is noticeably smaller in width and height, while being just a hair thicker.
leather plus size jackets
leather plus size jackets United States on 3/31/2010 7:56 PM Hiya. Thanks for all the information. On a side note, how do you deal with all the spammers you get on your site? My new blog is getting attacked by random spammers and I've been spending a lot of time and energy removing comments its just not funny. . I get so tired combating spam that I feed I need to stop running a blog completely.
cord blood banking
cord blood banking United States on 4/2/2010 12:19 PM This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like 'Mixview' that let you quickly see related albums, songs, or other users related to what you're listening to. Clicking on one of those will center on that item, and another set of "neighbors" will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune "Social" is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.
spectramed
spectramed United States on 4/4/2010 11:10 AM Awesome stuff you guys got here.  I really like the theme of the website and how well you organized the content.  It's a marvelous job I will come back and check you out sometime.
top exercise dvds
top exercise dvds United States on 4/5/2010 1:19 AM Hello everyone. This blog was unbelievable! Plenty of terrific info and inspiration. Keep 'em coming... you all do such a fantastic job at writing... can't let you know how much I, for one admire all you do!
Reverse Cell Phone Lookup
Reverse Cell Phone Lookup Uruguay on 4/5/2010 8:39 PM Interesting post Smile What a super blog!
dial direct
dial direct United States on 4/5/2010 9:10 PM Interesting read, thanks for helping keep me busy at work ;)
outsurance
outsurance United States on 4/6/2010 12:56 AM Some facts in this article are really true and very useful in life.
Bryon Geringer
Bryon Geringer Lithuania on 4/6/2010 11:49 AM Man.. I'm not a great deal into reading about this subject , but somehow I got to read a great deal of articles on your webpage. Its wonderful how interesting it is for me to visit you very often.
Fanny Bartels
Fanny Bartels Caribbean on 4/6/2010 10:08 PM Whats happening, I discovered this site about this subject by error when I was going through Google next I arrived to your web site. I have to say your web site is interesting I really like your theme! Right now I don�t have the free time at the current moment to completely browse your sitebut I have bookmarked it. I will be back in a day or 2 . Thanks for a great site.
Chris Politz
Chris Politz El Salvador on 4/7/2010 4:02 AM Couldnt be written any better about this subject . Reading this column reminds me of my old room mate! He always kept talking about this. I'll forward this informative article 2 him. Pretty certain he will have an excellent read. Thankfulness 4 sharing!
Sam Minskey
Sam Minskey Qatar on 4/7/2010 5:14 PM Dude.. I am not much into reading about this subject , but somehow I got to read lots of articles on your webpage. Its superb how interesting it is for me to visit you very often.
medical aid
medical aid United States on 4/7/2010 6:00 PM Nice post thanks.
Glenda Baughman
Glenda Baughman United States on 4/8/2010 3:22 AM I really like your post. Always been very informational. I hope you'll keep up the good work and maintain the standard. Best of luck.
auto insurance
auto insurance United States on 4/8/2010 3:25 AM Interesting read, thanks for helping keep me busy at work ;)
Lesley Long Island
Lesley Long Island United States on 4/8/2010 7:13 AM HO YA this subject this subject this subjectI have been browsingonline a lot more than 3 hrs today, nevertheless I never found any interesting article like yours about this subject It's pretty worth enough for me. In my opinion, if all site owners and bloggers made high-quality content as you did, the web will probably be far more practical than ever before.
Maynard Long Island
Maynard Long Island Lithuania on 4/8/2010 12:50 PM Positive site, where did u invent some the knowledge with this posting? I'm happy I found it though, ill be checking back soon to find out what additional articles you include.
locksmith in philadelphia
locksmith in philadelphia Costa Rica on 4/12/2010 4:38 AM this subject this subject this subject I entirely consider the above note, the internet is having a doubt growing into crucial medium of communication across the globe and its because of web sites similar to this that ideas are spreading so quickly
247philadelphialocksmith
247philadelphialocksmith Malaysia on 4/12/2010 1:28 PM I was wondering what is up with that bizarre gravatar??? I do know  5am is early & I am not looking my best at that hour, however I trust I do not seem like this! I'd however make that face if I'm inquired to complete 100 pushups. Smile|Smile}
AVG Antivirus Review
AVG Antivirus Review United States on 4/13/2010 12:46 PM Thank you for this helpfull review. It really was helpfull. Keep up the good work.
locksmith service
locksmith service Mexico on 4/14/2010 6:19 AM this subject this subject this subject Hello, U write some extremely appealing blogs. I always check back here time and again to view in case you have updated
locksmith fun
locksmith fun Saudi Arabia on 4/14/2010 1:13 PM this subject this subject this subject Hello, You mark some very worthy of note blogs. I always check back here regularly to see if you have updated
upholstered dining armchairs
upholstered dining armchairs United States on 4/14/2010 1:51 PM I normally dont take the time to leave comments, however it is difficult to find good information on this topic today. You did a fantastic job in this post and I may just go read your other blog posts now. Keep writing!
rap instrumentals
rap instrumentals United States on 4/16/2010 3:14 PM The useful code you wrote here... i can make time now to use it..leave this site momentarily and be back for ,more of your blog. Thanks for this post.
Rapidshare
Rapidshare United States on 4/17/2010 10:54 AM This paper explains most popular file hostings, their basics and functionality, gives you an overall idea about Rapidshare and its abilities, describes Rapidshare search engines, how they work and how to benefit from using them, when searching for files and folders on Rapidshare.

Before we get to the description of Rapidshare search engines, read this general most popular file hostings services report. Of course, as almost all Internet surfers, you have undoubtedly heard about Rapidshare and other similar services, made to help surfers easily spread music, videos, documents, software and other media and files over the Internet. Initially launched in German sector of the Internet in early 2000s , Rapidshare quickly became the most popular file share service in the world, which led to creation of an worldwide-targeted version used by more than 200 million people across the world. As a result of popularity of this file share service, first Rapidshare search engines appeared on web less than one year ago. If you\'re in need of sharing vacation pictures with your family, if you need to spread some documents and files with your colleagues without sending separate copies to each e-mail, just use Rapidshare to let people easiliy and instantly download the files from everywhere.

Moreover, you\'ve surely seen plenty of blogs and forums sharing files through Rapidshare and Rapidshare search engines helping people finding files on Rapidshare. It helps saving bandwidth and provide file links to their visitors. So, as you can see Rapidshare is a helpful, world famous fileshare that allows people, companies, creators and others instantly share content over the web.

At the same time, there is one deficit. Rapidshare won\'t let you search for for content in their database. Despite of that you are sure that a necessary file is almost surely hosted on Rapidshare and you can take it, you\'re unable to find it, since they haven\'t got a search engine.

That\'s exactly where Rapidshare search engines become useful. Rapidshare search engines are very similar to classic search engines with one important difference. They are not indexing sites - such engines only index Rapidshare and other fileshares, that\'s how you always get download links without any unnecessary garbage. Try Rapidshare search engine and you will definitely find all the files you need in several seconds!

Now it is time, let\'s evaluate major types of Rapidshare search engines available on the Internet. Basically we can outline three basic types: classic, advanced and full-featured rapidshare search engines. Basic search engines offer only one service. Their home pages usually contain only a search string. That\'s it. You type a search term, hit the search button, look through the results and download your file. Major disadvantage of services like this is that they\'re unable to show related and linked files, they don\'t check files for consistency and they don\'t crawl other file storages, except for Rapidshare. They provide only basic services, but to be honest, they are not worth a penny. Next type covers a bit more advanced Rapidshare search engines offering linked searches, check files for consistency and suggest likely and related files. However, they can\'t let you search on other file share services and they miss essential features of full-featured services. Now leading Rapidshare search egines are providing you a maximum of possible options combining many useful features and crawling many popular web file shares, including Rapidshare and it\'s derivatives. As you can assume it is obvious that it is your goal to find a leading Rapidhsare search egnine to take what you need at this type of search engines.
Rapidshare files search
Rapidshare files search United States on 4/17/2010 11:50 AM This document features most popular file hostings, their fundamentals and functionality, introduces you to the basics of Rapidshare and its features, describes Rapidshare search engines, the way they work and how to make them work for you, when looking for for files and folders on Rapidshare.

Before describing Rapidshare search engines, read this general most popular file hostings services observation. As well as many other web users, you have definitely heard about Rapidshare and similar-looking sites, invented to help surfers easily distribute videos, music, documents, software and other media and files over the web. First released in German web years ago, Rapidshare became the most popular file share within several years in the world, which led to invention of an international version used by more than 200 million people across the world. Due to popularity of this file share service, first Rapidshare search engines appeared on the Internet about one year ago. If you are in need of sharing vacation photos with your friends, if you need to spread some files and documents with your colleagues without sending separate copies to each e-mail, just use Rapidshare to let people easiliy and instantly download the files from any computer connected to the Internet.

Besides this, you\'ve definitely came across many blogs and forums sharing file links through Rapidshare as well as Rapidshare search engines that help people finding files there. This way they save bandwidth and share necessary files among their visitors. So, as you can see Rapidshare is a helpful, world famous fileshare that helps people, companies, creators and others easily share everything you want over the web.

And yet, they have a deficit. Rapidshare does not provide search services for content on Rapidshare. And although you know that a necessary file is almost definitely hosted on Rapidshare and you can download it, you\'re unable to find it, because they miss a search engine.

This is the point where Rapidshare search engines become handy. Rapidshare search engines are similar to Google, Yahoo and other search engines with one exception. They are not indexing sites - such search engines just index Rapidshare and other file share services, that\'s how you always get straight links without any unnecessary garbage. Give Rapidshare search engine a try and you will most likely find everything you need in several seconds!

Now, let\'s take a look at basic types of Rapidshare search engines available out there. Generally we can outline three typical classes: classic, advanced and full-featured rapidshare search engines. Basic search engines offer poor services. Their home pages usually contain only a search string and popular keywords. And no additional helpful features. You type in your keyword, click the Search button, look at the results and get the file. Major disadvantage of this type of services is that they\'re unable to show related and linked files, they don\'t check the files for availibility and consistency and they fail to index other file shares, other than Rapidshare. Basically they are good, but to be honest, they are not worth a penny. Next type covers a bit more advanced Rapidshare search engines that offer related searches, check the files for availibility and consistency and offer related and linked files. Again, they won\'t let you search on other file share websites and they miss essential features of top quality projects. Now quality Rapidshare search egines are ready to provide you a maximum of possible services covering many useful features and indexing many popular Internet fileshares, besides of Rapidshare and it\'s derivatives. As you can see it is obvious that it is your goal to find a best Rapidhsare search egnine to get all you need from this sort of services.
Lucien Dopp
Lucien Dopp Singapore on 4/20/2010 5:08 AM Love your web blog I will subscribe
Lydia Danielson
Lydia Danielson Uruguay on 4/22/2010 5:51 PM You made some good points there about this subject . I did a search on the topic and found most people will agree with your blog.
cord blood banking
cord blood banking United States on 4/24/2010 6:59 AM This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like 'Mixview' that let you quickly see related albums, songs, or other users related to what you're listening to. Clicking on one of those will center on that item, and another set of "neighbors" will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune "Social" is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.
locksmiths
locksmiths El Salvador on 4/27/2010 5:42 PM that is just what I was trying to find
Upholstered Dining Chairs
Upholstered Dining Chairs United States on 4/29/2010 8:32 PM I will try this. That't interesting code.
just locksmith
just locksmith United States on 4/30/2010 8:47 AM AAA post
Esteban Seville
Esteban Seville Nicaragua on 5/2/2010 2:50 AM this subject this subject this subject Hello, You write some extraordinarily attractive blogs. I always check back here time and again to see if you have updated
vacuum beard trimmer
vacuum beard trimmer United States on 5/2/2010 6:28 AM Hopefully this comment does not turn up various times (it seems to hang up once I endeavor to write my remarks... so I am unsure if it's essentially posting), but all I really wanted to say... terrific post! And thank you for writing out your thoughts..
play games
play games United States on 5/4/2010 1:24 AM There are actually large quantities of sources available on this. It could take months to study everything. you have brought it all up, so it really is all accessible here, in this blog.

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading