나는 ASPxGridView
과 ObjectDataSource
을 포함하는 ASP.NET 웹폼 페이지가 있습니다의 GridView
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Email { get;
public string Password { get; set; }
public string Telephone { get; set; }
}
ObjectDataSource
는 Update
메서드를 호출
<dx:ASPxGridView ID="gvEmployees" runat="server"
AutoGenerateColumns="False" DataSourceID="objDsEmployees"
KeyFieldName="EmployeeId">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True" />
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="EmployeeId" VisibleIndex="1" />
<dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="2" />
<dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="3" />
<dx:GridViewDataTextColumn FieldName="Telephone" VisibleIndex="5" />
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource ID="objDsEmployees"
runat="server"
ConflictDetection="CompareAllValues"
DataObjectTypeName="MySite.Data.Models.Employee"
DeleteMethod="Delete"
OldValuesParameterFormatString="original{0}"
InsertMethod="Insert"
SelectMethod="GetAll"
TypeName="MySite.Services.EmployeeService"
UpdateMethod="Update" />
직원 모델은 다음과 같은 속성을 포함을 서비스 계층에서 :
public void Update(Employee employee, Employee originalEmployee)
{
_db.Employees.Attach(originalEmployee);
_db.Entry(originalEmployee).CurrentValues.SetValues(employee);
_db.SaveChanges();
}
Update
메서드를 호출하면 매개 변수 employee
및 originalEmployee
에는 ASPxGridView
의 열로 사용되는 속성 만 포함되고 다른 속성 (예 : Password
)은 null입니다.
어딘가에 이러한 값을 보존 할 수있는 방법이 있습니까? 그건 그렇고, 나는 데이터 액세스를위한 엔티티 프레임 워크와 GridView의 DevExpress를 사용한다. 있습니다
public void Update(int employeeId, string name, string email)
{
var employee = GetById(employeeId);
employee.Name = name;
employee.Email = email;
_db.SaveChanges();
}
다른 솔루션 그러나보다 더 환영합니다 :에 서비스 계층에서
<asp:ObjectDataSource
ID="objDsEmployees"
runat="server"
DeleteMethod="Delete"
InsertMethod="Insert"
SelectMethod="GetAll"
TypeName="MySite.Services.EmployeeService"
UpdateMethod="Update">
<UpdateParameters>
<asp:Parameter Name="employeeId" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="email" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
그리고 Update
방법 :