Consuming data from SQL

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    3 posts
    Member since:
    Sep 2010

    Posted 02 Aug 2012 Link to this post

    Hi can you please tell me if the following approach the best for consuming the data from SQL utilizing WebService. 
    The following code is working correctly. However I need to know if I'm designing dataSource correctly. At this stage I'm only intending to read the data.

    DataViewModel

    public class LedgerViewModel
    {
        public int? lindex { get; set; }
        public int? linvoice { get; set; }
        public string lperiod { get; set; }
        public decimal? lamount { get; set; }
    }

    WebService

    [WebMethod(Description = "Gets ledger info")]
           public List<LedgerViewModel> Read()
           {
                
               using (var db = new LedgerConnection())
               {
                   return db.ledgers.Where(x => x.lmatter == "2007714")
                       .Select(l => new LedgerViewModel
                       {
                           lindex = l.lindex,
                           linvoice = l.linvoice,
                           lamount = l.lamount,
                           lperiod = l.lperiod
                       }).ToList();
               }
           }

    Sample WebService Output

    <ArrayOfLedgerViewModel>
      <LedgerViewModel>
        <lindex>698567</lindex>
        <linvoice>871181</linvoice>
        <lperiod>0511</lperiod>
        <lamount>0.0000</lamount>
      </LedgerViewModel>
      <LedgerViewModel>
        <lindex>698568</lindex>
        <linvoice>871181</linvoice>
        <lperiod>0511</lperiod>
        <lamount>0.0000</lamount>
      </LedgerViewModel>
    </ArrayOfLedgerViewModel>

    Kendo UI dataSource

    dataSource: {
          transport: { }
              read: {
                  url: "GetLedger.asmx/Read",
                  contentType: "application/json; charset=utf-8",
                  type: "POST"
              }
          },
          schema: {
              type: "xml",
              data: "/ArrayOfLedgerViewModel/LedgerViewModel",
              model: {
                  fields: {
                      linvoice: "linvoice/text()",
                      lperiod: "lperiod/text()",
                      lamount: "lamount/text()"
                  }
              }
          },
            sort: {
                field: "lperiod",
                dir: "asc"
            }
        }

  2. Daniel
    Daniel avatar
    3 posts
    Member since:
    Sep 2010

    Posted 05 Aug 2012 Link to this post

    Anyone ?
Back to Top