locked
What are InsertParameters for ? RRS feed

  • Question


  • Hello,

    I'm using EntityDataSource and I'm trying to use InsertParameters to automatically set the parent relationship of the created entity. Is this possible ? Smile What are InsertParameters then used for as EntityDataSource does not have any insert command ?

    Thanks,
    Andrei
    Monday, June 23, 2008 7:04 PM

Answers

  • Andrei,

    First face, the “Trainings.ID” name seems ok, since this is the same way you are calling in your where clause.

    I have a very similar scenario working perfectly here, but that is with more recent bits. So, two possibilities come to mind:

    1.       That the issue is a bug that has been fixed since SP1 beta, in which case a possible workaround is to handle the Inserting event and assign the value on the new entity in code.

    2.       If Trainings.ID is actually part or a composite entity key in TestInstances, EntityDataSource won’t flatten the Traininsgs.ID property. Instead it will only expose the standard scalar property that is part of the key. In this case, the right name to use in the InsertParameter will be TrainingsID or however the key property is called.

    Hope this helps,
    Diego

    Sunday, June 29, 2008 1:41 AM

All replies

  • Hello Andrei,

    Yes, you should be able to use the InsertParameters to supply newly inserted entities with values for properties that are not bound to any field in the databound control.

    EntityDataSource control does not have an Insert method, but the underlying EntityDataSourceView object that databound controls communicate with has it.

    As a side note, if you think you need access to the Insert() method yourself, you could do it after casting the control to the IDataSource interface and invoking the GetView() method.

    Hope this helps,
    Diego

    Wednesday, June 25, 2008 12:14 AM

  • Thanks for your answer, still, I don't get it Smile
    I have an EntityDataSource along with a ListView with InsertTemplate. I bound most of the fields except the parent relation, so I have the following error as the parent entity is not supplied:

    Entities in 'TrainingEntities.TestInstances' participate in the 'FK_TestInstances_Trainings' relationship. 0 related 'Trainings' were found. 1 'Trainings' is expected.

    I'm adding TestInstances where Trainings is the parent entity.
    So I want to use InsertParameters to set the parent entity in the insertion process (by retrieving the parent entity's id from a DropDownList).

    Here's my EntityDataSource:

    <asp:EntityDataSource ID="EntityDataSourceTests" runat="server"
                ContextTypeName="TrainingModel.TrainingEntities" EntitySetName="TestInstances" Where="it.Trainings.id=@trainingid"
                EnableInsert="true" EnableUpdate="true" >
                <WhereParameters>
                    <asp:QueryStringParameter QueryStringField="Trainings.id" Name="trainingid" Type="Int32" />
                </WhereParameters>
                <InsertParameters>
                    <asp:ControlParameter ControlID="DropDownListTrainings" Type="Int32" Name="Trainings.id" />
                </InsertParameters>
            </asp:EntityDataSource>

    I don't know what parameter name to specify for the InsertParameter for it to work.
    Please help! Smile Thanks
    Saturday, June 28, 2008 1:36 PM
  • Andrei,

    First face, the “Trainings.ID” name seems ok, since this is the same way you are calling in your where clause.

    I have a very similar scenario working perfectly here, but that is with more recent bits. So, two possibilities come to mind:

    1.       That the issue is a bug that has been fixed since SP1 beta, in which case a possible workaround is to handle the Inserting event and assign the value on the new entity in code.

    2.       If Trainings.ID is actually part or a composite entity key in TestInstances, EntityDataSource won’t flatten the Traininsgs.ID property. Instead it will only expose the standard scalar property that is part of the key. In this case, the right name to use in the InsertParameter will be TrainingsID or however the key property is called.

    Hope this helps,
    Diego

    Sunday, June 29, 2008 1:41 AM

  • It doesn't work with Trainings.id and that is not part of a composite entity key.
    It *does* work though using Dynamic Data controls i.e. using a ForeignKey control that somehow inserts the correct parameter.
    Monday, June 30, 2008 8:23 AM