Giving up on EntityDataSource
- Sorry is this supposed to work?
With a flat object and no relationships this might work.. or for simply displaying object data.. But inserting and updating objects with related objects this doesn't work.
The problem, and it is expressed in many different ways, is the datasource doesn't seem to know what to do with forgein key references to related objects on inserts and updates.
Someone tell me i am wrong or i am correct so i can stop trying.. Anyone.. please. Or direct me to a working example of someone successfully using entitydatasource to update or insert objects and their related objects.
Answers
- I see the post is a little old, but I started in the same boat. Your entityDataSource needs to have an Include="x,y,z" property where x, y, and z are the navigation properties of the table in your .edmx file. The navigation properties represent the foreign keys in the table in the database itself, but may not have the same name.
<asp:EntityDataSource ID="edsNotes" runat="server" Include="D_CLASS_SESSION, D_USER, D_STATUS" AutoGenerateWhereClause="True" ConnectionString="name=ChrisEntity" DefaultContainerName="FACULTYINTAKEEntities" EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntitySetName="D_NOTE" Where="" AutoGenerateOrderByClause="True" OrderBy="" EntityTypeFilter="" Select="" > <OrderByParameters> <asp:Parameter Name="DATE_ENTERED" /> </OrderByParameters> <WhereParameters> <asp:Parameter DefaultValue="1" Name="IS_TASK" /> </WhereParameters> </asp:EntityDataSource>
Good luck!Les Berg- Marked As Answer byNoam Ben-Ami - MSFT1MSFT, ModeratorThursday, September 03, 2009 8:43 PM
All Replies
To clarify: I assume you have a model where the primary key of one entity type is also a foreign key to another type? Could you perhaps share that part of your model? Could you share how you set up the bindings in your page?
This posting is provided "AS IS" with no warranties, and confers no rights.- Hi Noam, thanks for responding.
In my model, it looks like:
[
assembly: global::System.Data.Objects.DataClasses.EdmRelationshipAttribute("PropurchaserM2Alpha2Model", "FK_CostDriver_CostDriverType", "CostDriverType", global::System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(PropurchaserEntitities.CostDriverType), "CostDriver", global::System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(PropurchaserEntitities.CostDriver))]
Not sure if that is what you are looking for.. But the relationship itself is working fine with linq queries and in the objects itself.
In the formsview the bindings look like:
<
tr>
<td>
CostDriverType:
</td>
<td>
<Telerik:RadComboBox ID="RadComboBox2" runat="server"
DataSourceID="EntityDSCostDriverTypes" DataTextField="costDriverTypeName"
DataValueField="costDriverTypeID">
</Telerik:RadComboBox>
<asp:EntityDataSource ID="EntityDSCostDriverTypes" runat="server"
ConnectionString="name=PropurchaserM2Alpha2Entities"
DefaultContainerName="PropurchaserM2Alpha2Entities"
EntitySetName="CostDriverTypes">
</asp:EntityDataSource>
</td>
</tr>
the ItemTemplate displays the info fine.. no problems there. But when trying to update i am getting a generic "object reference not set to...." ..
When i inspect the newvalues collection coming from the formsview everything seems to look correct.. no missing values. although the key looks like CostDriver.CostDriverType .. Not sure if this is an issue.
thanks for your time!
Rich - I see the post is a little old, but I started in the same boat. Your entityDataSource needs to have an Include="x,y,z" property where x, y, and z are the navigation properties of the table in your .edmx file. The navigation properties represent the foreign keys in the table in the database itself, but may not have the same name.
<asp:EntityDataSource ID="edsNotes" runat="server" Include="D_CLASS_SESSION, D_USER, D_STATUS" AutoGenerateWhereClause="True" ConnectionString="name=ChrisEntity" DefaultContainerName="FACULTYINTAKEEntities" EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntitySetName="D_NOTE" Where="" AutoGenerateOrderByClause="True" OrderBy="" EntityTypeFilter="" Select="" > <OrderByParameters> <asp:Parameter Name="DATE_ENTERED" /> </OrderByParameters> <WhereParameters> <asp:Parameter DefaultValue="1" Name="IS_TASK" /> </WhereParameters> </asp:EntityDataSource>
Good luck!Les Berg- Marked As Answer byNoam Ben-Ami - MSFT1MSFT, ModeratorThursday, September 03, 2009 8:43 PM

