私は心を失いつつあります。それは単純なシナリオです:FormViewで使用されるすべてのEntityプロパティがEntityDataSourceによってロードされているわけではありません。
のaspxファイル内のエンティティ定義(生成)
// 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;
}
..
<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>
...
// ... 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
}
基本的には専用のプロパティの背後にあるコードでフォームビューでバインドされている値は、Updateイベントハンドラで利用できます。キーでe.Contextからエンティティをリロードすると、それらのプロパティだけが再び取得されます。
何がありますか? Updatingイベントでエンティティのすべてのプロパティにアクセスするにはどうすればよいですか? また、データソースにインクルードが含まれている場合、それらの値はUpdatingイベントで使用できません。何が起こっているの、助けてください!
私はちょっと後で自分自身を考え出しました。私はそれが吸うと思うが、まあまあ。あなたはカルマを手に入れなければならないので、答えを探している他の人はそれを得ることができます。乾杯! – Strelok