CodeSmith Community
Your Code. Your Way. Faster!

Custom Stored Procedure Insert/Delete error status

Latest post 12-06-2006 1:58 PM by ovalsquare. 3 replies.
  • 11-30-2006 3:38 PM

    Custom Stored Procedure Insert/Delete error status

    Off and on I've been searching through the forums to discover the best way to handle this. I have two custom stored procedures: one to insert a record and one to delete a record. They're custom procedures as they don't fit an entity structure because they need to check on a related table a couple tables up the line - not worth deep loading - and have some custom logic requirements.

    I am utilizing EAB error handling, and have it set not to rethrow errors. As the rest of the application is designed around this, I'd prefer not to have to change this in order to accomodate this small aspect of the application. My problem is that inserts and delete custom stored procedures are always void. Even if there is an error thrown, it's caught by EAB and there's no way of knowing at the UI level the transaction's success.

     For my Insert one, I did a dummy entity creation:

    if user_name() is null
    BEGIN
        SELECT FolderId, ImageId FROM FoldersImages WHERE 1=0
        RETURN
    END

    And then after all the logic takes place, I do a select to return a T<List> of the new record and check on the count. If < 0 I've got a problem and I can act accordingly (count will only ever be 1 as it's a junction table that doesn't allow for duplicate values). However this is extremely crufty - there must be a better way! Optimally there would be a boolean success sent back up the line, but I know that this is not supported. I have the same problem with the delete proc.

    Does anyone have any suggestions? Or is the above the best way to reliably tell if there's an error or not? Or should I rethrow all errors already caught by the EAB, and catch them again?

    Much thanks,

    Ted

    • Post Points: 35
  • 12-01-2006 11:40 AM In reply to

    Re: Custom Stored Procedure Insert/Delete error status

    Reply |Contact |Answer

    The EAB isn't caught or used until the Component/ServiceLayer, so what you should do, is a simply wrap those custom methods with a facade your own logic in the user class of your Provider.

     DAL/Bases/MyEntityProviderBase.cs

    public bool CustomMethodFacade(int param1) //duplicate method call
    {
        try{
               RealCustomMethod(param1);   //just a passthrough
             }
        catch
        {
               return false;
         }
        return true;
    }
     


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 12-01-2006 3:59 PM In reply to

    Re: Custom Stored Procedure Insert/Delete error status

    Thanks for your response Robert. I am always amazed at the quickness of responses to questions posted in the forum - it's why I hesitate to ask something right away as I'm sure there must be an answer already posted to someone's similar question before.

    I'll be implementing a facade sometime in the next couple weeks and will keep you posted.

    • Post Points: 5
  • 12-06-2006 1:58 PM In reply to

    Re: Custom Stored Procedure Insert/Delete error status

    Thanks again Robert.

    My one clarification for anyone looking at this later on is to log the exception with EAB before returning false, otherwise your exception is swallowed up.

    Ted

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