List method does not return objects

Asked

Viewed 181 times

0

Method with RU List

internal List<Arquivo> GetAllArquivo()
    {
        using (var ctx = new TESTEntities())
        {
            var arquivos = (
                    from ver in ctx.ARQUIVO
                    select new Arquivo()
                    {
                        ARQUIVO_GUID = ver.ARQUIVO_GUID,
                        XARQUIVO = ver.XARQUIVO,
                        TAG = ver.TAG,
                        URL = ver.URL,
                        EXTENSAO = ver.EXTENSAO,
                        IS_STREAM = ver.IS_STREAM,
                        ULT_ARQUIVO_VERSAO_GUID = ver.ULT_ARQUIVO_VERSAO_GUID,
                        TIPO_DE_ARQUIVO_GUID = ver.TIPO_DE_ARQUIVO_GUID,
                        DIRETORIO_GUID = ver.DIRETORIO_GUID
                    }
                ).ToList();

            return arquivos;
        }
    }

I want to access the method data to return a specific object: ex:

meuDal.GetAllArquivo().XARQUIVO

However you find nothing, I have other list methods that work, and that.

  • Unfortunately I can not help this, so I see nothing wrong (but I may be missing something) and I can not test this excerpt). But I have a curiosity and a hint. Why do you like to use these handles in uppercase? Did you know that for cases like this you can use one foreach ordinary? LINQ was not made to do what you do with it. If it is to take the data without manipulating them in any way and materialize them then and then only work with the materialized, it is better to assemble the list without LINQ. It’s easier and faster.

  • When you call myDal.Getallafile() it returns a File list, if you want to get 1, do so myDal.Getallafile(). Firstordefault(). SYRUP

  • Unfortunately it is project ready that I took I can not opine yet(Then I will question about this).

  • It worked @Paulohdsousa vlw, how do I pick up a particular Dice? in java use the get(i)

  • puts as answer the solution.

  • 1

    @moustache the only thing I see of why these wrong syntax in this project c#, is that this system is a webservice, which will be consumed by old clients(Delphi programmers) and maybe they are used to this form, and have made this c# with the Attributes like this, maybe just to facilitate others, is totally wrong but I can not opine yet(Then I will seek to know)

Show 1 more comment

1 answer

1


When you call meuDal.GetAllArquivo() it returns a list of File, if you want to catch 1, do so meuDal.GetAllArquivo().FirstOrDefault().XARQUIVO

It will return the first record from the list,

If you want a specific one, you can do so:

meuDal.GetAllArquivo().Where(a => a .ARQUIVO_GUID == 'uid').FirstOrDefault().XARQUIVO
  • It worked, thank you very much!

  • that a=> means what?

  • It is the way of making queries in ENTITY with LAMBDA, I prefer so than the way you do. http://www.caelum.com.br/apostila-csharp-orientacao-objetos/linq-e-lambda/ Link comparing LAMBDA and LINQ:https://msdn.microsoft.com/pt-br/library/jj128159.aspx

  • thanks I’ll take a look.

  • @Warlock when you have any questions about something you read in any answer, there is a good chance you already have another answer on Sopt about this. And if you don’t, you should probably ask someone to get the question. In this case see: http://answall.com/q/34907/101 And remember that you can vote for everything on website, in the answers given to you, in other answers, in questions. Acceptance is not the only way to reward the content posted by all.

  • All right, I’m gonna go with that...

Show 1 more comment

Browser other questions tagged

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