Azure 테이블 저장소에 저장 한 일부 레코드의 유형을 나타내는 클래스입니다.Azure 테이블 저장소에서 레코드를 업데이트하기 위해 동일한 유형의 두 인스턴스를 병합하는 방법
public class UserType : TableEntity
{
public enum eGenderType { None, Male, Female }
public virtual DateTime BornDate { get; set; }
public Guid ConfirmationCode { get; set; }
public virtual string Email { get; set; }
public virtual bool? Enabled { get; set; }
public virtual string FirstName { get; set; }
public virtual eGenderType Gender { get; set; }
public virtual string Surname { get; set; }
public UserType Get()
{
TableQuery<UserType> Query = new TableQuery<UserType>().Where("PartitionKey eq '" + Email + "' and RowKey eq '" + ConfirmationCode + "'");
UserType User = GetFromTable(Query).FirstOrDefault();
Type InstanceType = GetType();
foreach (PropertyInfo Property in typeof(UserType).GetProperties(BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
PropertyInfo InstanceProperty = InstanceType.GetProperty(Property.Name, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (Property.PropertyType.IsValueType && Equals(InstanceProperty.GetValue(this), Activator.CreateInstance(Property.PropertyType)))
InstanceProperty.SetValue(this, Property.GetValue(User));
else if (InstanceProperty.GetValue(this) == null)
InstanceProperty.SetValue(this, Property.GetValue(User));
}
return this;
}
public void Update()
{
SaveToTable(); // Perform an InsertOrReplace operation on Azure Table Storage
}
}
public class UserModel : UserType
{
public void SetFullName()
{
Get();
base.Update();
}
}
그런 다음 HTTP POST 요청에서 데이터를 가져와 데이터 모델로 사용되는 UserModel 객체에 바인딩하는 MVC 작업이 있습니다.
[HttpPost]
public void SetFullName(UserModel Model)
{
Model.SetFullName();
}
내가 전체 레코드를 업데이트 할 필요가 푸른 표 저장소에 레코드를 업데이트하려면 내가 모델에서 한 번 새로운 업데이트 이전의 데이터가 필요하므로 나는 하나의 필드를 업데이트 할 수 없습니다. 이 경우 Model 객체에서 값이있는 속성 (전자 메일, ConfirmationCode, 이름 및 성) 만 있습니다. base.Update가 Table에서 값을 가져 오는 범위를 갖기 전에 호출하는 Get() 메서드를 값이없는 속성의 Model 개체에 넣습니다.
테이블 이름과성에 null이 있고 모델에 값이있는 경우 업데이트 작동 및 레코드가 이전 값과 새 값으로 올바르게 업데이트됩니다. 하지만 다른 경우에는 테이블 이름과성에 값이 있고 모델에 null 인 경우 Get 메소드는 Model 객체에 이전 성과 이름을 null 값 대신 업데이트 후 테이블에 넣습니다. 항상 오래된 가치를 지녔습니다.
그래서 올바른 방법은 무엇입니까? 내 접근 방식이 맞습니까?