Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, much too many hours later I found the solution myself:</p> <p><b>Option 1:</b></p> <p>It is possible to use the <b>select</b> property in the EntityDataSource which allows to create arbitrary projections of data from several related entities/database tables (in my case: OrderID from Order entity and City from the Address entity)</p> <p>Drawback: Using <b>select</b> in the EntityDataSource makes using Insert, Update and Delete in the GridView impossible!</p> <p><b>Option 2:</b></p> <p>The EntityDataSource must have the <b>include</b> property to include the related address property along with the queried orders. The markup looks likes this:</p> <pre><code>&lt;asp:EntityDataSource ID="EntityDataSourceOrders" runat="server" ConnectionString="name=MyEntitiesContext" DefaultContainerName="MyEntitiesContext" EntitySetName="Order" Include="Address" EnableDelete="True" EnableInsert="True" EnableUpdate="True"&gt; &lt;/asp:EntityDataSource&gt; </code></pre> <p>Then the columns collection of the GridView can have a template field like this:</p> <pre><code>&lt;asp:TemplateField HeaderText="City" &gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="LabelCity" runat="server" Text='&lt;%# Eval("Address.City") %&gt;'&gt; &lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre> <p>Here <b>Eval</b> is important. <b>Bind</b> does not work. Also using a <b>BoundField</b> as a column...</p> <pre><code>&lt;asp:BoundField DataField="Address.City" HeaderText="City" /&gt; </code></pre> <p>... is <b>NOT</b> possible. So it is not possible in the GridView to edit the City (which makes sense because its a related field belonging to another table and perhaps to many other orders). But it is possible to edit flat fields of the order entity and also the "AddressID" of the order to assign another address.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload