locked
ListView will not do Insert RRS feed

  • Question

  • User-1425666379 posted

     I am trying to add a ListView to a custom page that I am using to insert new Child "Comment" records that are related to a Parent "CreditRequest" entity. The parent data is displayed in GridView1 at the top of the page. I can't seem to figure out how to get the insert to occur because it doesn't seem to know what the foreign key is. I keep getting a message that says

    "Entities in 'PDCCreditRequestEntities.Comment' participate in the 'FK_Comment_CreditRequest' relationship. 0 related 'CreditRequest' were found. 1 'CreditRequest' is expected."

    I have a ListView with an InsertTemplate and an EntityDataSource as follows. I'm guessing I need to add InsertParameters on my EntityDataSource, but I can't seem to get that right. Any ideas? And yes, I've gotten to the point of flinging code at it just to see what works.

                 <asp:ListView ID="ListView_Comments" runat="server" 
                        DataSourceID="CommentsDataSource"
                        DataKeyNames="CommentID"
                        DataMember="CommentID" 
                        InsertItemPosition="LastItem" >
                        <ItemTemplate>
                            <tr >
                                <td></td>
                                <td><asp:DynamicControl runat="server" DataField="CommentID" /></td>
                                <td><asp:DynamicControl runat="server" DataField="CommentText" /></td>
                                <td>td>
                            </tr>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <tr>
                                <td><asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /></td>
                                <td><asp:DynamicControl runat="server" DataField="CommentID" /></td>
                                <td><asp:DynamicControl Mode=Insert runat="server" DataField="CommentText" /></td>
                                <td></td>
                            </tr>
                        </InsertItemTemplate>
                        <LayoutTemplate>
                              <!--Contains ItemPlaceholder-->
    	    </LayoutTemplate>
                    </asp:ListView>
     
    <!--EntityDataSource-->

     

                    <asp:EntityDataSource ID="CommentsDataSource" runat="server" 
    		EntitySetName="Comment"
                        	DefaultContainerName="PDCCreditRequestEntities" 
    		EnableInsert="true" 
                        	ContextTypeName="PDCCreditRequestEntities" 
    		Include="CreditRequest">
                        <WhereParameters>
                            <asp:DynamicControlParameter Name="CreditRequest" ControlId="GridView1" />
                        </WhereParameters>
                      <InsertParameters>
    		<!--???-->
                        </InsertParameters>                    
                    </asp:EntityDataSource>
    <?xml:namespace prefix = asp /><asp:Parameter< span><asp:DynamicControlParameter< span><asp:Parameter< span><asp:DynamicControlParameter< span><asp:ControlParameter< span><asp:DynamicControl< span><asp:TextBox< span><asp:TextBox< span><asp:DynamicControl< span></asp:DynamicControl<></asp:TextBox<></asp:TextBox<></asp:DynamicControl<></asp:ControlParameter<></asp:DynamicControlParameter<></asp:Parameter<></asp:DynamicControlParameter<></asp:Parameter<><asp:Parameter< span><asp:DynamicControlParameter< span><asp:Parameter< span><asp:DynamicControlParameter< span><asp:ControlParameter< span><asp:DynamicControl< span><asp:TextBox< span><asp:TextBox< span><asp:DynamicControl< span>
    </asp:DynamicControl<></asp:TextBox<></asp:TextBox<></asp:DynamicControl<></asp:ControlParameter<></asp:DynamicControlParameter<></asp:Parameter<></asp:DynamicControlParameter<></asp:Parameter<>
    Tuesday, August 26, 2008 5:18 PM

Answers

  • User-1425666379 posted

    This issue is solved here and here

     Jeff

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 25, 2008 6:04 PM

All replies

  • User-797310475 posted

     Could you provide a full stack trace of the error you are seeing?

    Wednesday, August 27, 2008 12:56 AM
  • User-1425666379 posted

    How is this?: (I think the real problem is that I don't know how to properly implement the InsertParameters in this case, I can't figure out how to get the InputParameter to pass on the key)

    [UpdateException]: Entities in 'PDCCreditRequestEntities.Comment' participate in the 'FK_Comment_CreditRequest' relationship. 0 related 'CreditRequest' were found. 1 'CreditRequest' is expected.
       at System.Data.Mapping.Update.Internal.UpdateTranslator.RelationshipConstraintValidator.ValidateConstraints()
       at System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
       at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
       at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
       at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
       at System.Data.Objects.ObjectContext.SaveChanges()
       at System.Web.UI.WebControls.EntityDataSourceView.ExecuteInsert(IDictionary values)
       at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback)
       at System.Web.UI.WebControls.ListView.HandleInsert(ListViewItem item, Boolean causesValidation)
       at System.Web.UI.WebControls.ListView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
       at System.Web.UI.WebControls.ListView.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.ListViewItem.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    [HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown.
       at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.default_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website10\c15e2502\44180099\App_Web_euftr9h5.0.cs:line 0
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Wednesday, August 27, 2008 1:12 PM
  • User-1425666379 posted

    I posted the stack trace. Do ForeignKey Field templates have anything to do with this? Is there something explicit I need to do with those?

    Wednesday, August 27, 2008 4:43 PM
  • User-1425666379 posted

    Marcin, I restated the problem a little more clearly here: http://forums.asp.net/t/1322323.aspx

    I'm not getting an error with the new code, but the insert is done to the wrong record for some reason. I think this may possibly just be an EF problem, but no one on that forum is responding.

    Can you either direct me to some documentation on this or provide me with a solution? I'm floundering here...

    Friday, September 19, 2008 5:10 PM
  • User-1425666379 posted

    This issue is solved here and here

     Jeff

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 25, 2008 6:04 PM