The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

esDataSource and SqlException

Last post 11-14-2007, 8:32 PM by Mike.Griffin. 5 replies.
Sort Posts: Previous Next
  •  10-24-2007, 8:16 AM 6030

    esDataSource and SqlException

      Hi,

        I have an application that uses esDataSource, FormView and GridView. How (and where) can I handle an SqlException such as:

     [SqlException (0x80131904): The DELETE statement conflicted with the REFERENCE constraint "". The conflict occurred in database "", table "", column ''.
    The statement has been terminated.]
       EntitySpaces.Web.esDataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +719
       System.Web.UI.WebControls.FormView.HandleDelete(String commandArg) +839
       System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +556
       System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +109
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +163
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

       Thanks for any help.

  •  10-24-2007, 8:43 AM 6031 in reply to 6030

    Re: esDataSource and SqlException

    Yes, go into design mode, look at the events available on the esDataSource and double click on the esException event, any and all exceptions ecountered by the esDataSource will be routed there as long as you have an event handler.You can even set the ExceptionWasHandled flag if you want the esDataSource to ignore the exception (meaning you took care of it) and it will not rethrow it.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  11-14-2007, 4:46 PM 6553 in reply to 6031

    Re: esDataSource and SqlException

    I'm not sure if this is the right place for this, but I am finding that esDataSource doesn't handle Hierarchical Collections too well.

    One thing I have found is that if a parent class has a property with the same name as the child you cannot bind or sort without an exception.

    For example:
    Say you have this data structure:

    MasterEntity
    ------------------
    MasterEntityId
    Name

    ChildEntity
    ---------------
    ChildEntityId
    Name
    ChildEntityNumber
    MasterEntityId

    If you perform a search on the ChildEntityNumber like so:

    MasterEntityQuery me = new MasterEntityQuery("meq");
    MasterEntityCollection mec = new MasterEntityCollection();
    ChildEntityQuery ce = new ChildEntityQuery("ceq");
    me.InnerJoin(ce).On(me.MasterEntityId == ce.MasterEntityId);
    me.Where(ce.ChildEntityNumber == param);
    mec.Load(me);


    The collection loads fine, but when you bind to the esDataSource and sort it will generate this query:

    (FYI, sort is something like this)
    this.SearchResultsGV.Sort(MasterEntityMetadata.PropertyNames.Name, SortDirection.Ascending);


    exec sp_executesql N'WITH [withStatement] AS (SELECT *, ROW_NUMBER() OVER( ORDER BY [Name] ASC) AS ESRN FROM [MasterEntity] meq INNER JOIN [ChildEntity] ceq ON (meq.[MasterEntityId] = ceq.[MasterEntityId]) WHERE ceq.[ChildEntityNumber] = @ChildEntityNumber1) SELECT * FROM [withStatement] WHERE ESRN BETWEEN 1 AND 2',N'@ChildEntityNumber1 int',@ChildEntityNumber1=12345


    Which will generate a SqlException like this:


    Msg 209, Level 16, State 1, Line 1
    Ambiguous column name 'Name'.
    Msg 8156, Level 16, State 1, Line 1
    The column 'Name' was specified multiple times for 'withStatement'.


    There are actually two problems here. The Order By does not quality Name to the table, and Name will appear twice in the With statement.

    Not sure how easy it is to address these, but thought it might help to have some feedback.

  •  11-14-2007, 5:30 PM 6554 in reply to 6553

    Re: esDataSource and SqlException

    I think what you are saying is esDataSource doesn't support the new join syntax? right? Can you please post a new thread with your entire .cs (code behind only) file in here using the code button, this is very important for us to look at before this release goes out this weekend. You kind of hi-jacked this one.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  11-14-2007, 7:39 PM 6557 in reply to 6554

    Re: esDataSource and SqlException

    Mike, will do.
  •  11-14-2007, 8:32 PM 6559 in reply to 6557

    Re: esDataSource and SqlException

    Also, I think you need a Select clause, in join scenarios you are required to declare at least one column in a select, in non join scenario's its Select * but we cannot do that in joins.  To select all from a column in a join you pass the query in, like this:

    e.Select(e, od.OrderName);

    that's the same as "e.*, od.OrderName) 

     

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML