나는 때때로 디버깅을 수행 할 때 null null을 허용하지만 설정에 의해 게시물 갤러리를 제거 할 때 문제가 발생하지만 중단 점, 그것은 null 값이 아닙니다. 어떻게이 문제를 해결할 수 있습니까? 에스테 codigo : 여기엔티티 프레임 워크 4.3.1 null null 외래 키를 설정하는 방법
var postold = _postRepositorio.ObterPorId(postDto.Id);
if (postold.ImagemCapa != postDto.ImagemCapa && !String.IsNullOrEmpty(postDto.ImagemCapa) && !String.IsNullOrEmpty(postold.ImagemCapa))
{
if (
File.Exists(
System.Web.HttpContext.Current.Server.MapPath(
Path.Combine(ConfigurationManager.AppSettings["DiretorioImagem"], postDto.ImagemCapa))))
{
File.Delete(
System.Web.HttpContext.Current.Server.MapPath(
Path.Combine(ConfigurationManager.AppSettings["DiretorioImagem"], postold.ImagemCapa)));
}
}
var editPost = AutoMapper.Mapper.Map(postDto, postold);
editPost.CategoriaPost = _categoriaPostRepositorio.ObterPorId(postDto.CategoriaPost);
editPost.Galeria = postDto.Galeria == 0 ? null : _galeriaRepositorio.ObterPorId(postold.Id);
_postRepositorio.Editar(editPost);
_contexto.SaveChanges();
내가 갤러리
editPost.Galeria = postDto.Galeria == 0? null: _galeriaRepositorio.ObterPorId (postold.Id);
이것은 매우 분명하지 않습니다. "때로는 null을 허용하지만", "중단 지점 일 때 퇴각" 문제가 정확히 무엇입니까? –
문제는 외래 키가 null 값을 허용하지 않는다는 것입니다. –
확실하지 않지만 최선의 방법은 외래 키 null 값을받는 방법입니다. do {editPost.Galeria = null; } while (editPost.Galeria! = null);' –