Last post Jun 06, 2017 05:28 AM by JBetancourt
Jun 05, 2017 05:38 PM|rkrex|LINK
I was wondering what type of data is returned when you use a normal call to a sql server database as
opposed to using json data. Or whats the advantage of using json data. Also, can I use linq to sql in my web method to return the data from the
sql server database? Thanks !
Jun 05, 2017 05:55 PM|JBetancourt|LINK
sql server doesnt have a rest interface as long as I know, the drivers create a permanent connection to the server(until closed) and manage the connection and data transfer but you have no control over that.
You can use json between the client side of your application and the back end side, that is up to you, the standards that were used before json were mainly xml and soap for wcf services, json is more lightweight that the other standards
To use linq to return data from sql server you use an ORM (Object Relational Mapper) like entity framework, in ef you create a dbcontext that allow to access your database using linq expressions, like var products = db.Products.Where(p=>p.price<10).ToList();
Jun 05, 2017 06:48 PM|rkrex|LINK
Thank You very much for your reply. But I was wondering how is the json data different from the data coming from sql server? Is it in a format that's more suited
for using it with objects or classes in your application? I'm just tring to get a better understanding of whats going on under the hood. I know that ajax is asynchronous meaning it
eliminates the post backs but I am wanting to understand the advantages as it relates to crud operations of using json data. Thanks again !!!
Jun 06, 2017 05:28 AM|JBetancourt|LINK
you dont see and have no control on how sql server driver transfer the data to your application and most likely is some binary very compacted way to minimize the size of the data packages. this happens from your sever side code to the sql server.
ajax calls are made from your your client side code to your backend, it can be synchronous as well although not recommended as it will freeze the browser until finished. you are right in that it "eliminates the post back" speaking on terms of asp.net, in
the sense that you can use it to call the server (with the page loaded) and once you get the result you can rerender just the piece of the page that depends on this new data, increasing the performance of your page as there is no need to refresh the whole
page which will happen if you do a postback.
now json is a data format used to represent and transmit data in text format (sql server wont use it as transmitting binary data is more efficient, not human readable though)
metadata information in a json object as you can include in xml format.