Create webapp with full stored procedures - asp.net

I want to create a web application, all actions (Create, Update, Delete) should be done using SQL stored procedure. Every action in the web just calls a stored procedure and receives json data to render the view.
So what is the best framework that I can use? Please help

So what is the best .Net framework that I can use?
Every .Net Framework has ways to retrieve data from database. So, it doesn't really matter what version of .NET Framework you use.
I believe you would like to know what kind of library you should use for Store Procedures. If so, you might want to look at Dapper ORM.
Dapper ORM is created by Stack Exchange, and used in a lot of sites including Stack Overflow.
It basically is a wrapper around ADO.NET to map SQL result to strongly type object. If you have to do the mapping manually, it is very tedious and error prone process. So, I highly recommend using Dapper ORM if you have to call Store Procedures.

Related

using linq and entity framework to iterate over database data

I read that in some books they use linq to sql and entity framework..
Whats so good about them?!!?
They are slow.. especially linq to sql. Does entity framework have any benefit that make it worth learning?!?
I strive to make the site as fast as I can, and I dont use disconnected data access much
consider that my goal is to make the site run as fast as it can
ORM frameworks like Linq-to-Sql and Entity Framework will almost always implement an abstraction layer between the program code and database SQL statement. This layer's job is to parse the code's syntax into a SQL statement.
So, if your ultimate goal is increased speed, it would be smart to avoid that layer.

ADO.NET Entity Framework better than the method I am using?

I have read a bit about ADO.NET Entity Framework, but there is some things I am missing. Right now (not using EF, not sure what this technique is called, just ADO.NET?) we store all procedures in the database, that way if we have to change anything we have to just go into the db and change a query, pretty easy (other than the fact I have 100s of queries).
If I am correct with EF, I can query easier (no joins, shorter queries) but everything is saved in the Entity Data Model. So if I needed to change a query I would have to launch VS go in, find the location and change the query (which I guess would be linq-to-sql or Entity SQL to perform the query)
I just need some clarification about EF, and Entity SQL vs Linq-to-SQL.
Thank you!
When using EF you can use several types of data accessing:
Enity SQL - it is syntax similar to common SQL but queries are directly in code or entity model. If you want to change query you must rebuild and redeploy application.
Linq-to-entities - Linq queries on top of entity model. Again if you want to change query you must rebuild and redeploy application.
Executing stored procedures imported to model (also known as function import) - this is just sotred procedure exposed on your ObjectContext as .NET function. EF will handle parameters and result mapping.
Executing direct SQL by ExecuteStoreQuery or ExecuteStoreCommand (only EFv4). Here you can call any SQL including stored procedures.
So with EF you have both your current approach plus EF itself. Moreover calling native SQL through EF has some advantages like automatic mapping to prepared classes.
Anyway what you describe is quite uncommon situation. In many companies modifying something in DB requires same process as modifying application (or even more complicated) so you can't simply go and modify stored procedure in production.

Rewrite the same asp.net application again

I have a asp.net application which is written in the traditional method [SqlConnection. SqlAdapter.. ..] in data access layer, I can see that every time we are making a connection and using adapters. Code is written in a very dirty manner. I have been given the task to re write the application in standard/best practice way.
i have all stored procedure already written, is there any way I can use a tool like which will help me in writing the business layer and data access layer?
I suggest you to go for codesmith. As you have all the Stored procedure already written you can either go for the LINQ to SQL feature.
For the DAL, you could use Entity Framework 4. The business logic could be wrapped up by hand.
Take a look at fluentAdo.net. You can use it with all your old stored procedures.
But if you really want to rewrite your app, I suggest you to use NHibernate or Entity Framework. They have pretty same set of fetures.

Linq vs Stored Procedure

Which one is preferable for Enterprise CMS development:
LINQ or SP?
Generally what I do is LINQ to Views and LINQ to Stored Procedures. It's not a question of what is preferred because LINQ solves how to manage the data once it's queried where Stored Procedures are run on the SQL side to allow for query manipulation (or for me, mostly saving) of data which takes away from having the code to do it which is slower.
I would say you would want to use both if necessary. Are you saving to Entities that require multiple tables saves as one Entity? If so, use Stored Procedures with LINQ. If you're using 1 to 1 Entity relations to your tables then just use LINQ.
Stored Procedures can be used with Linq2Sql (and Entity Framework), so it isn't a choice of one or another.
I would cache the results from the database for a CMS as you likely to get the same data requested over and over again (cache the dataset, or use page caching, or cache the objects if using LINQ).
Then it doesn't matter if you use LINQ or an SP, but I would just use LINQ.
For simple CRUD table(no joins !!!) operations LINQ to SQL is fine, however for anything more complex (needing joins) I always use stored procedures (you can use Linq to stored procedures if you wish)
There are numerous debates around this on this site and others. For me, you can normally split the pro Linq camp into guys who have recently come into programming and have not had the history of having to use Stored procedures, ie not been heavily involved in the database side of previous projects.
Form my experience of working on several projects using pure LINQ, stored procedures and a mixture of both these are the two reasons I would stick to Linq for basic CRUD and stored procedures for anything more complex or relying on performance.
1 - Deploymenty/Security - Anyone that has worked in the real world a knows full well that having the database logic separated into stored procedures and not incorporated into the source code and released DLL is a massive advantage. You can add a proper security/access layer around each query using roles and SQL server security, imperative for any serious enterprise level company, and you can also make changes to the SQL of any stored procedure without having to do a new release of the main application (dll). I dont care how good you claim to be we have all had to fix live issues and performance bottlenecks using stored procedures and having to do this with a new application release would have been a nightmare.
2 - Performance/Code Smells - I have seen so many applications littered with huge amount of of badly written and inefficient Linq. Developers get lazy with Linq, little hidden lazy Linq to SQL queries which cause you a nightmare trying to debug performance issues on an enterprise level system - the motto 'get it done as quick as possible' seems prevalent. I have seen more Spaghetti code since the advent of Linq than I had seen with any previous class library/pattern Microsoft have released since COM.

Best Data Access Methods for New Web Application

I'm building a new web application project and am confused by the numerous methods of performing data access. I'm backending on SQL and a bit confused whether to use LINQ to SQL or trtaditional ADO.net ?
what are the advantages and disadvantages of using LINQ/SQL over ADO.net?
If it is ADO.net,then what is the best way to retrieve data means either calling the stored procedures or directly calling the t-sql code?
My question is what is cleanes and most effiecient and professional way of creating DAL for webapplication in asp.net?
Thanks
What are the advantages and
disadvantages of using LINQ/SQL over
ADO.net?
Linq2sql generates a series of
classes that are 1-to-1 mappings of
your (selected) database tables - this means you don't have to write tedious and error prone data access code
using ado.net yourself.
Linq2sql may not provide enough value for you if you intend on using a custom object-to-relational mapping (non 1-to-1) - of course you could still use linq2sql, but it would mean having an extra layer in between.
Linq2sql allows you to easily query the database using powerful linq expressions. Writing linq queries provides you with intellisense that you wouldn't get if you embedded your queries as strings inside ado.net commands, or wrote stored procs in management studio.
Using linq, you don't need to know t-sql while you will if you use ado.net (although it can definitely an advantage if your linq queries start doing strange things!). An example of this the complexity of writing t-sql queries that provide paging resultsets simply becomes .Skip(page * size).Take(size).
Linq2sql automatically creates t-sql that uses parameterised queries which is much more secure against sql injection attacks than handwritten ado.net code which builds up a query using a string.
Linq2sql doesn't work very well with stored procedures - you are probably better off not bothering with linq2sql if using sprocs.
Linq2sql could require your database tables to be less-tightly locked down than would be possible writing ado.net code using stored procedures.
If it is ADO.net,then what is the best
way to retrieve data means either
calling the stored procedures or
directly calling the t-sql code?
If you'd ruled out linq2sql, and ado.net happened to the better choice for data retrieval, I would be surprised if you were directly calling t-sql code very often or even at all. I would almost certainly expect you to be using stored procedures for reasons that you have queries that are too complex using linq, and/or security requirements.
My question is what is cleanest and most effiecient and professional way of creating DAL for webapplication in asp.net?
In my opinion, the cleanest DAL would probably use linq2sql as it is the lightest and most targeted ORM for SQL Server (assuming your still interested in SQL Server for this specific question of course).
The most efficient could be the handwritten one using ado.net, but this is probably a waste of time as more often than not, you will find a tool such as linq2sql writing better queries than 90% of developers.
In my opinion, the most professional DAL could be linq2sql, but it is more likely to be the Entity Framework of NHibernate (as other answers have suggested) due to more flexibility.
My last choice DAL in terms of cleanliness and professionalism would definitely be a handwritten ado.net one.
The best way to go is O/RM. Small apps Linq2Sql, larger apps Entity Framework 4 or NHibernate (Fluent NHibernate).
Calling SPs from your code means that your app logic is placed somewhere else than in the app code. It's a way to go but at present less and less popular because of TDD.
The best way is to create DAL into a separated logic layer, own assembly.
I would without doubt go for Linq2Sql.
Download Linqpad and play around with the included samples to get started.
You should check out some ORM frameworks, like NHibernate: http://nhibernate.info
If you want efficient data access in terms of performance than there is nothing faster than pure ADO.NET. You chan check it out here: http://ormbattle.net/.

Resources