我有这个实体
public class Account : ValidationModel, IFormattable
{
private int id;
private string cardNumber;
private string username;
private string password;
private string fullName;
......
public Account()
{
this.id = 0;
this.username = String.Empty;
this.password = String.Empty;
this.fullName = String.Empty;
................
}
public int Id
{
get { return id; }
set { SetProperty(ref id, value); }
}
[Required(ErrorMessageResourceName = "EnterUsername", ErrorMessageResourceType = typeof(Resources))]
public string Username
{
get { return username; }
set { SetProperty(ref username, value); }
}
[Required(ErrorMessageResourceName = "EnterCardNumber", ErrorMessageResourceType = typeof(Resources))]
public string CardNumber
{
get { return cardNumber; }
set { SetProperty(ref cardNumber, value); }
}
[Required(ErrorMessageResourceName = "EnterPassword", ErrorMessageResourceType = typeof(Resources))]
public string Password
{
get { return password; }
set { SetProperty(ref password, value); }
}
[Required(ErrorMessageResourceName = "EnterFullName", ErrorMessageResourceType = typeof(Resources))]
.......
}
当我想验证这个实体时,我会像这样调用accountInstance.Validate()
string errorMessage = account.Validate();
if (!string.IsNullOrEmpty(errorMessage))
{
messageService.ShowError(errorMessage);
return;
}
它将验证所有属性。现在,我想要排除ID,密码,用户名 如何在不改变实体框架的DataContext的情况下在C#中执行此操作?