开发者

stored procedure result set into what kind of .NET object for Json.NET serializer?

I am developing ASP.NET web application that will use a lot of AJAX calls through jQuery开发者_StackOverflow社区 to retrieve data from database. So I want to incorporate some good approach to handle this calls. I thought of using web handlers for each AJAX call. This calls would then return data in JSON format and jQuery code will be used to manipulate and display JSON data on webpages.

Inside web handlers I would get data from sql database through stored procedures. I thought of using Json.NET serializer for converting result set into JSON. And my question is in what kind of C# .NET object should I put stored procedure's result set so I can work on it with serializer? (any examples or tips will be great) I kinda don't like the idea of using datareader and then looping through it and building JSON myself with stringbuilder or something..

thx


I would consider writing your own business objects (C# classes that model the data you want to serialize as JSON) and using Entity Framework to map these to your database tables and stored procedures. Mark your business classes with the [Serializable] attribute and you should be away.


For pain-free and fast reading from DB I would suggest Dapper.

Just declare classes that map to your result sets and use Dapper to populate them, ie:

IEnumerable<User> user = connection.Query<User>("spGetUsers",  
    new {Id = 1},  
    commandType: CommandType.StoredProcedure);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜