Thursday, April 25, 2013

ASP.NET - Data Access Guidance


Microsoft has published Data Access Guidance for ASP.NET 4.5. Most of the changes are related to new features in 4.5, such as those in Web Forms and the new ASP.NET Web API.Some notes from the guidance -
Use ORMs wherever possible with ASP.NET Web Forms and MVC, but ADO.NET directly (through the Database helper) in ASP.NET Web Pages
For WebForms data controls
For Displaying a Single Record - Use FormView to customize generated HTML; for maximum automation of HTML generation use DetailsView
For Displaying Lists - Use ListView to customize generated HTML; Repeater for customized HTML but read-only access and better efficiency (but lesser advanced features); and GridView for maximum automation of HTML generation
ASP.NET Web Forms data binding methods -
Data Source Controls for simple binding without writing any code
Model Binding when it is feasible to write data retrieval and update code
Manual Data Binding when fine-grained control over binding needed or model binding not supported
Data-Binding Expressions
Eval and Bind for weakly typed data
Bind and BindItem for strongly typed data
Use colon in opening delimiter (<%#:) to enable automatic HTML-encoding
Notably, there is a guidance on how to choose between WCF Data Services and ASP.NET Web API for your web services -Choose WCF Data Services if you want to quickly expose a database over HTTP for use inside a firewall on an internal company network.Conversely, choose Web API for Internet-based services because the whitelist approach is more secure than the blacklist approach.WCF uses a black-listing approach to security restrictions (by default everything is made available) whereas Web API uses a white-listing approach (by default nothing is made available)There are a lot of walkthroughs for various scenarios covered on MSDN – you can refer it for more details.

No comments:

Post a Comment