Suppose I have two classes, one derived from EntityObject
and the other derived from the first:
public class Gizmo : EntityObject { ... }
public class SpecialGizmo : Gizmo { ... }
In the ASP.NET page, the user selects a Gizmo in a list (a GridView
) and that Gizmo’s details are then presented in a DetailsView
. The goal is for the user to be able to view and edit the details.
Here is the relevant DetailsView
and its associated EntityDataSource
:
<asp:DetailsView ID="GizmosDetailsView" DataSourceID="dsGizmoDetails"
AutoGenerateEditButton="True" AutoGenerateInsertButton="True"
AutoGenerateRows="False" DataKeyNames="GizmoId" runat="server">
<Fields>
<asp:BoundField DataField="GizmoId" HeaderText="GizmoId" ReadOnly="True" SortExpression="GizmoId" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<!-- ... etc. --->
</Fields>
</asp:DetailsView>
<asp:EntityDataSource ID="dsGizmoDetails" runat="server" ConnectionString="[...]"
DefaultContainerName="[...]" EnableFlattening="False" EnableUpdate="True"
Where="it.[GizmoId] = @GizmoId">
<WhereParameters>
<asp:ControlParameter ControlID="gvwGizmos" Name="GizmoId" PropertyName="SelectedValue" Type="Int64" />
</WhereParameters>
</asp:EntityDataSource>
The above fails with the following exception:
InvalidOperationException: Either CommandText or EntitySetName must be defined.
That’s understandable. However, both options presented break something:
If I add
EntitySetName="Gizmo"
, then only entities of actual typeGizmo
are ever presented. If aSpecialGizmo
is selected, the DetailsView comes up blank.If I add a
CommandText
(or aSelect
) attribute, then theDetailsView
no longer supports updating the data. A working “edit” button (that makes edit UI appear) is there, but then clicking “Update” after making edits simply does nothing.
Is there a proper solution to this dilemma?