원인, 나는 업데이트()를 호출 방법은 항상 NullReferenceException이를 던져 것으로 나타났습니다. 이는 3.0.0.3 릴리스에 포함 된 샘플 MVC 다운로드에서도 마찬가지입니다.음속 SimpleRepository 업데이트는 음속의 새로운 SimpleRepository 연구에서 null 참조 예외
업데이트가 성공할 수있는 방법이 있는지 아는 사람 있습니까?
다음은 예입니다. if 문이 작동합니다. 테이블을 추가하고 레코드를 만듭니다. 이 코드를 else 블록으로 두 번째로 실행하면 업데이트에서 예외가 throw됩니다.
var repo = new SimpleRepository("c", SimpleRepositoryOptions.RunMigrations);
var user = repo.Single<User>(u => u.Email == "[email protected]");
if (user == null)
{
repo.Add(new User { Email = "[email protected]", Name = "Test" });
}
else
{
user.Name = DateTime.Now.ToString();
repo.Update(user);
}
public class User
{
public int Key { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}