locked
Select multiple Column with linq RRS feed

  • Question

  • User615038210 posted

    Hi

    I want to select multiple column......with linq query 

    display data in json format and use jquery autocomplete method.......

     <script>
    
            $("#search").autocomplete({
                source:'@Url.Action("GetCustomer")'
            })
        </script>
    <p><input type="text" id="search" class="search" name="search" /></p>
    List<string> custo;
    custo = (from N in context.customeres
             where N.CutomerName.StartsWith(term) && N.NumberofCutstomerDID.StartsWith(term).select(x => new {x.CutomerName,x.NumberofCutstomerDID})
             



    Sunday, December 25, 2016 12:46 PM

All replies

  • User-271186128 posted

    Hi balvindersingh,

    Select multiple Column with linq

    As for this issue, please try to modify your code as below: remove the dot before the select keyword.

    custo = from b in context.customers
            where b.CutomerName.StartsWith(term) && b.NumberofCutstomerDID.StartsWith(term)
            select new {};

    Best regards,
    Dillion

    Monday, December 26, 2016 2:49 AM
  • User615038210 posted

    Thanks Zhi...for reply to this question.........

    Monday, December 26, 2016 4:15 AM
  • User615038210 posted
    Hi

    i'm getting this error when i'm using this code.so how can i'm select these two field in select new{ }
    please review this screenshot and let me know how can i'm resolve this issue..............

    http://my.jetscreenshot.com/29458/20161226-nrmo-48kb.png
    Monday, December 26, 2016 6:35 AM
  • User516094431 posted

    Try below line of code:

    var customers = (from b in context.customers
            where b.CutomerName.StartsWith(term) && b.NumberofCutstomerDID.StartsWith(term)
            select new {  b.CutomerName, b.NumberofCutstomerDID}).Tolist();



    Monday, December 26, 2016 7:03 AM