I am losing my mind. It's a simple scenario:
Entity definition (generated)
// this class is obviously generated by the designer, this is just an example
public class SomeEntity {
public int SomeEntityID { get; set; } // primary key
public String Property1 { get; set; }
public String Property2 { get; set;
}
.. in aspx file
<asp:EntityDataSource
ID="EntityDataSource1" runat="server"
ConnectionString="name=Connection" DefaultContainerName="SomeEntities"
EnableDelete="True" EnableInsert="True" EnableUpdate="True"
EntitySetName="SomeEntity" OnUpdating="UpdatingEntity" AutoGenerateWhereClause="true">
<WhereParameters>
<asp:QueryStringParameter Name="SomeEntityID" QueryStringField="SomeEntityID" Type="Int32"/>
</WhereParameters>
</asp:EntityDataSource>
<asp:FormView runat="server" ID="FormView1" DataSourceID="EntityDataSource1">
<EditItemTemplate>
<asp:TextBox runat="server" ID="textbox1" Text='<%# Bind("Property1")%>'
</EditItemTemplate>
</asp:FormView>
... in code behind
// ... as per Diego Vega's unwrapping code
public TEntity GetItemObject<TEntity>(object dataItem)
where TEntity : class
{
var entity = dataItem as TEntity;
if (entity != null)
{
return entity;
}
var td = dataItem as ICustomTypeDescriptor;
if (td != null)
{
return (TEntity)td.GetPropertyOwner(null);
}
return null;
}
protected void UpdatingEntity(object sender, EntityDataSourceChangingEventArgs e) {
SomeEntity entity = GetItemObject<SomeEntity>(e.Entity);
// at this point entity.Property1 has the value of whatever was entered in the
// bound text box, but entity.Property2 is null (even when the field bound to this
// property in the database contains a value
// if I add another textbox to form view and bind Property2 to it ... then I can
// obviously get its value from the entity object above
}
Basically ONLY the properties bound in the form view have their values available in the Updating event handler, worse still when I try to reload the entity from e.Context by key, I get only those properties again.
What gives? How can get access to all the properties of the entity in the Updating event? Also if the datasource contains Include, those included values are NOT available in the Updating event. What's going on, please HELP!