This is a migrated thread and some comments may be shown as answers.

Consuming data from SQL

1 Answer 106 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 03 Aug 2012, 01:40 AM
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"
        }
    }

1 Answer, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 06 Aug 2012, 01:36 AM
Anyone ?
Tags
Data Source
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Share this question
or