locked
ASP.NET newbie - should I learn ADO.NET or EF? RRS feed

  • Question

  • User1694074641 posted

    Hi All,

    My background

    • I am very familiar with SQL Server, stored procedures, indexing, queries etc.
    • Now learning ASP.NET for the first time (learning ASP.NET Core with C#)
    • Just learnt ADO.NET and considering learning EF or Dapper

    Dilemma

    • Should I learn EF or stick to ADO.NET?
    • It seems a bit confusing

    My data access choices for my web projects

    • ADO.NET + stored procedures 
      I would have dozens of stored procedures for even the simplest SQL queries and just call each stored procedure when needed
      Benefit of this choice is that I don't have to learn EF which I think is a big topic on its own

    • EF with or without stored procedures
      Is learning EF necessary if I am not working for someone else?
      Just creating web apps for my own
      Is it hard to learn EF?
      If I plan to use stored procedures exclusively (and not LINQ), would I be better off just sticking to ADO.NET?

    If I choose the first option (ADO.NET + stored procedures), would I be missing some benefits?

    Appreciate all your advice.

    Sunday, November 8, 2020 1:40 PM

Answers

  • User-821857111 posted

    Before learning how to use an ORM like EF or Dapper, I think you should spend a bit of time learning about the problems that they are intended to solve.

    The biggest problem that you have when working ADO.NET is that the data containers that it provides (DataReaders and DataTables) are not strongly typed. So it is very easy to mistype a column name when using a reader or table, and end up with runtime errors complaining that the index is out of bounds etc. Or you might change a column or table name in your DB and then find that your datareaders still reference the old column name.

    Dapper doesn't solve these problems because it doesn't generate SQL based on the column and table mappings, but EF does. Both of them enable you to work with data as strongly typed objects instead of string or numeric indexers (rdr["FirstName"] etc).

    If you plan to stick with your own SQL (as stored procs or inline) I would recommend that you look at Dapper rather than EF (https://www.learndapper.com). If you find that you prefer to work with data as objects having done that, then you might want to look at EF Core out of interest, if nothing else (https://www.learnentityframeworkcore.com)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 8, 2020 4:46 PM

All replies

  • User-821857111 posted

    Before learning how to use an ORM like EF or Dapper, I think you should spend a bit of time learning about the problems that they are intended to solve.

    The biggest problem that you have when working ADO.NET is that the data containers that it provides (DataReaders and DataTables) are not strongly typed. So it is very easy to mistype a column name when using a reader or table, and end up with runtime errors complaining that the index is out of bounds etc. Or you might change a column or table name in your DB and then find that your datareaders still reference the old column name.

    Dapper doesn't solve these problems because it doesn't generate SQL based on the column and table mappings, but EF does. Both of them enable you to work with data as strongly typed objects instead of string or numeric indexers (rdr["FirstName"] etc).

    If you plan to stick with your own SQL (as stored procs or inline) I would recommend that you look at Dapper rather than EF (https://www.learndapper.com). If you find that you prefer to work with data as objects having done that, then you might want to look at EF Core out of interest, if nothing else (https://www.learnentityframeworkcore.com)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 8, 2020 4:46 PM
  • User475983607 posted

    EF populates models while ADO.NET you'll need to write code to populate models.  

    Sunday, November 8, 2020 4:47 PM
  • User1120430333 posted

    f I choose the first option (ADO.NET + stored procedures), would I be missing some benefits?

    IMHO, you need to learn the basics of ADO.NET first before anything else.

    You write the words ADO.NET. But do you really know what ADO.NET is about, because there are books that cover ADO.NET? 

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-overview

    After all, it's called the ADO.NET Entity Framework,  and EF uses ADO.NET components.

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/overview

    Sunday, November 8, 2020 9:29 PM