나는 내 마음을 잃고 있습니다.FormView에서 사용되는 EntityDataSource에 의해로드 된 모든 Entity 속성이 없음
// ... 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
}
기본적으로
속성 만 뒤에 코드 (생성)
엔티티 정의
// 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>
의 : 그것은 간단한 시나리오입니다 폼 뷰에 바인딩 된 값을 Update 이벤트 핸들러에서 사용할 수 있습니다. 키로 e.Context에서 엔티티를 다시로드하면 해당 속성 만 다시 가져옵니다.
무엇을 제공합니까? Updating 이벤트에서 엔티티의 모든 속성에 액세스하려면 어떻게해야합니까? 또한 데이터 소스에 포함이 포함 된 경우 포함 된 값은 업데이트 이벤트에서 사용할 수 없습니다. 무슨 일이 일어나는지, 제발 도와주세요!
네, 나중에 나 자신을 알아 냈습니다. 나는 그것이 싫증 난다라고 생각한다. 그러나 오 오 잘. 카르마를 얻어야하므로 다른 사람들이 답을 구할 수 있습니다. 건배! – Strelok