Validation error in Entity framework

Asked

Viewed 154 times

0

In my method of adding ta files giving the following Exception when debugging:

Validation failed for one or more entities. See 'Entityvalidationerrors' Property for more Details.

Method:

  internal void AddArquivo(Model.Arquivo arquivo)
    {
        using (var ctx = new TESTEntities())
        {
            var versao = arquivo.ArquivoVersoes[0];
            ctx.ARQUIVO.Add(new ARQUIVO()
            {
                ARQUIVO_GUID = arquivo.ARQUIVO_GUID,
                ARQUIVO_VERSAO = new ARQUIVO_VERSAO()
                {
                    ARQUIVO_GUID = arquivo.ARQUIVO_GUID,
                    ARQUIVO_VERSAO_GUID = Guid.NewGuid().ToString(),
                    ARQUIVO = versao.ARQUIVO,
                    DATAHORA = versao.DATAHORA,
                    TAMANHO = versao.TAMANHO,
                    USUARIO_PESSOA_GUID = versao.USUARIO_PESSOA_GUID
                },
                DIRETORIO_GUID = arquivo.DIRETORIO_GUID,
                EXTENSAO = arquivo.EXTENSAO,
                IS_STREAM = arquivo.IS_STREAM,
                TAG = arquivo.TAG,
                TIPO_DE_ARQUIVO_GUID = arquivo.TipoDeArquivo.TIPO_DE_ARQUIVO_GUID,
                ULT_ARQUIVO_VERSAO_GUID = arquivo.ULT_ARQUIVO_VERSAO_GUID,
                URL = arquivo.URL,
                XARQUIVO = arquivo.XARQUIVO
            });
            ctx.SaveChanges();
        }
    } 
  • 1
  • 1

    @Warlock, you need a catch with a Dbentityvalidationexception, have a great example posted by Gypsy: http://answall.com/questions/38119/erro-ao-updateds-no-entity-framework/38175#38175

  • I did, it was in the context of my project, where I had GUID.neGuid.Tostring() so it generates a randomized Guid with characters, and in my context did not accept, so I used a library q already has ready in the project, which formed in the correct way, Util.Util.Guids.Getguid(),

  • @Tobymosque gives a look at the other theme I created, thanks.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.