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
WebService
Sample WebService Output
Kendo UI dataSource
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"
}
}