Wednesday, September 2, 2015

Convert List<Object> to DataTable using FastMember in C#.Net

Recently, I got the requirement to convert the List<Object> to DataTable. The ad-hoc way, which we have been following to loop through the List and create the DataTable – which I don’t want to do. Therefore, I found a very good way by using FastMember. All you have to do is to download the FastMember from NuGet. Following are the steps below to download the Fastmember

 


 

Search for fastmember, and then install it.

 


 

After completing the installation, just include the FastMember namespace – and with the help of ObjectReader class we will be able to convert List to DataTabe.

 

IEnumerable<Customer> customerData = GetAllCustomers();

            if (customerData.Count() > 0)

            {

                using (DataTable table = new DataTable())

                {

                    using (var reader = ObjectReader.Create(customerData, "CustomerId","CustomerName", "CustomerAddress"))

                    {

                        table.Load(reader);

                    }

                }

            }

 

  IEnumerable<Customer> GetAllCustomers()

        {

            Customer[] customers = new Customer[]

        {

            new Customer { CustomerId = 1, CustomerName = "Ali", CustomerAddress = "Pakistan" },

            new Customer { CustomerId = 2, CustomerName = "Wakeel", CustomerAddress ="Pakistan" },

            new Customer { CustomerId = 3, CustomerName = "Anthony", CustomerAddress ="England" }

        };

            return customers;

        }

 

GetAllCustomers() will return the Sample data. I believe this is one of the efficient and quickest way to process the Data. I Hope you all must have enjoyed it after implementing this code :)

 


 

              

 

 

40 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Great Sharing! . Thank you so much it resolved my problem.

    ReplyDelete
  3. Dot Net is an ever trending technology where it is more preferable by developers to utilize the features in the

    dot net language. your article on Dot Net language proves that it is an evergreen technology in the IT market.

    Best DOT NET Training institute in Chennai |
    DOT NET Training Chennai

    ReplyDelete
  4. I ‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.
    Hadoop Training Institute In chennai

    ReplyDelete
  5. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Hadoop Training in Chennai

    Hadoop Training in Bangalore

    Big data training in tambaram

    Big data training in Sholinganallur

    Big data training in annanagar

    Big data training in Velachery

    Big data training in Marathahalli

    ReplyDelete
  6. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.


    MEAN stack training in Chennai

    MEAN stack training in bangalore

    MEAN stack training in tambaram

    MEAN stack training in annanagar

    MEAN stack training in Velachery

    MEAN stack training Sholinganallur

    ReplyDelete
  7. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Devops Training in pune|Devops training in tambaram|Devops training in velachery|Devops training in annanagar
    DevOps online Training

    ReplyDelete
  8. Very well written blog and I always love to read blogs like these because they offer very good information to readers with very less amount of words....thanks for sharing your info with us and keep sharing.
    python training institute in chennai
    python training in velachery
    python training institute in chennai


    ReplyDelete
  9. I think you have a long story to share and i am glad after long time finally you cam and shared your experience.
    java training in marathahalli | java training in btm layout

    java training in jayanagar | java training in electronic city

    ReplyDelete
  10. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.

    Data Science training in Chennai
    Data science training in bangalore
    Data science training in pune
    Data science online training

    ReplyDelete
  11. Woah this blog is wonderful i like studying your posts. Keep up the great work! You understand, lots of persons are hunting around for this info, you could help them greatly.

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  12. Informative post indeed, I’ve being in and out reading posts regularly and I see alot of engaging people sharing things and majority of the shared information is very valuable and so, here’s my fine read.
    click here css
    click here call to action
    click here css animation
    click here to 2lz4drob
    click here click here click here

    ReplyDelete
  13. Right after the course job opportunities knocks your door. cursos de ti online

    ReplyDelete
  14. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.


    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery




    ReplyDelete
  15. Nice! you are sharing such helpful and easy to understandable blog. i have no words for say i just say thanks because it is helpful for me.

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery




    ReplyDelete
  16. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.thanks share!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  17. Absolutely professional and engaging training sessions helped me to appreciate and understand the technology better. thank you very much if our dedicated efforts and valuable insights which made it easy for me to understand the concepts



    hadoop training in chennai

    hadoop training in annanagar

    salesforce training in chennai

    salesforce training in annanagar

    c and c plus plus course in chennai

    c and c plus plus course in annanagar

    machine learning training in chennai

    machine learning training in annanagar

    ReplyDelete
  18. Very helpful blog post, explained everything very clearly, This blog really has all the info I was looking for. Thanks you for sharing. Electronics

    ReplyDelete
  19. This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.data scientist training in hyderabad

    ReplyDelete
  20. This is an awesome blog post by Tom Venuto. In it he explains why the Obama Stimulus Package should be
    Buy yahoo accounts considering a "Good" debt relief plan. The Federal Stimulus Package, or so they say, is being pushed on all media outlets to pump up consumer confidence, which should start a recovery in the US economy, and make us once again a beacon on the world stage. Okay, so let's talk about this for second shall we? Yes, absolutely, and here's why:Buy snapchat account

    ReplyDelete
  21. There are many important things in life to consider. Some of the most important things in life to consider are love, family, health, and survival. All of these things can be easily taken for granted, but they will be more appreciated if they are not taken for granted. There are also many importantBuy snapchat account things in life that we sometimes take for granted but never get around to doing. Some examples of these would be: having a job, getting out of bed in the morning, getting groceries, and taking care of your children.Buy Bulk Twitter accounts

    ReplyDelete
  22. Infycle Technologies, one of the best software training institutes in Chennai offers excellent Oracle PLSQL training in Chennai for freshers and students, and Tech Professionals of any field. Other demanding courses such as Java, Hadoop, Selenium, Big Data, Android, and iOS Development will also be trained with complete hands-on training. After the completion of training, the students will be sent for placement interviews in the core MNC's. Dial 7504633633 to get more info and a free demo.Excellent Oracle PLSQL Training Chennai | Infycle Technologies

    ReplyDelete
  23. Infycle Technologies, the No.1 software training institute in Chennai offers the No.1 Selenium course in Chennai for tech professionals, freshers, and students at the best offers. In addition to the Selenium, other in-demand courses such as Python, Big Data, Oracle, Java, Python, Power BI, Digital Marketing, Cyber Security also will be trained with hands-on practical classes. After the completion of training, the trainees will be sent for placement interviews in the top companies. Call 7504633633 to get more info and a free demo.

    ReplyDelete
  24. Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. data analytics course in surat

    ReplyDelete
  25. This post is so interactive and informative.keep update more information...
    SEO Training in Anna Nagar
    SEO Training in Chennai

    ReplyDelete
  26. Really awesome bog, informative blog and knowledgeable content. Thanks for sharing with us. If you want to become a data science expert, then check out the following link.
    Data Science Training Institute in Hyderabad with Placements

    ReplyDelete
  27. SlotyRoo Casino - Mapyro
    SlotyRoo Casino, Mapyro, Gauteng, South China. 2021-07-10 15:45 PM. Gauteng, China, South 안산 출장안마 China. Gauteng, 계룡 출장샵 China. Gauteng, China. 1086. 1096. 0.0. 0. 0. 0. 0. 0. 0. 안산 출장샵 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 부산광역 출장샵 0. 0. 0. 0. 인천광역 출장샵 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.

    ReplyDelete
  28. Buy tinder accounts- 100% Verified Faster Delivery Tinder is one of the largest social media sites and marketers are very active in the community where we can help grow your business with the Tinder PVA accounts

    ReplyDelete