CodeSmith Community
Your Code. Your Way. Faster!

Best way to update a single field in all Entities?

Latest post 09-25-2008 3:41 PM by SuperJeffe. 5 replies.
  • 09-25-2008 8:22 AM

    • iatek
    • Top 200 Contributor
    • Joined on 08-03-2007
    • Posts 22
    • Points 380

    Best way to update a single field in all Entities?

    Hi,

    I need to reset a counter (int) field to 0 in all instances of my "Content" entities. What is the best way to do this?

    I have thought of..

    1) TList using "GetAll" from ContentService, and setting the property=0 for the entire list. But I'm not sure if there is a short cut or if I need to iterate through the entire list to set the values.

    2) Executing a SQL Query using:
    DataRepository.Provider.ExecuteNonQuery(CommandType.Text, "UPDATE Content SET Counter=0");

    TIA for any recommendations.

     

    • Post Points: 35
  • 09-25-2008 8:36 AM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 444
    • Points 11,030

    Re: Best way to update a single field in all Entities?

    This is a perfect spot for a custom proc.  Sql Server does this much better than C#. 

    1.  You could create a function in the Content data repositoty that updated the value and called ExecuteNonQuery.  I would not put the Sql in anywhere other than the data layer.

    2.  Write a custom procedure from your Content table.  The proc would just update them all to 0.  Then, Nettiers will create the method for you.  This is what I would do.

    jeff

     

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 35
  • 09-25-2008 11:22 AM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 254
    • Points 6,460

    Re: Best way to update a single field in all Entities?

    Just be careful to follow your patern of development. If you're creating SPs for every single stuff you need, then creating a procedure as jeff suggested is the way to go. If you have no idea of what we're talking about OR has the option ExecuteSql set to false, then it would be better to create a method in your DA class to handle that for you.

    I would create a method in my DataLayer... but that's just because I hate SP's... (;

     

    • Post Points: 5
  • 09-25-2008 12:15 PM In reply to

    • iatek
    • Top 200 Contributor
    • Joined on 08-03-2007
    • Posts 22
    • Points 380

    Re: Best way to update a single field in all Entities?

    Thanks for your ideas.. I think I go with a method in the DAL, since I haven't been using a lot of SP's

    • Post Points: 35
  • 09-25-2008 3:34 PM In reply to

    • vbandrade
    • Top 25 Contributor
    • Joined on 09-27-2007
    • Brasil
    • Posts 254
    • Points 6,460

    Re: Best way to update a single field in all Entities?

    Yeah! SP's s**ks!!

     

    lol

    • Post Points: 35
  • 09-25-2008 3:41 PM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 444
    • Points 11,030

    Re: Best way to update a single field in all Entities?

    Lol, at least I mentioned both methods!

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems