0

Why using linq or entity-framework? Why not using data from ado.net directly,
for example select some data from table and show it directly in a datagidview?

Example :

con = new SqlConnection(cs.DBConn);
con.Open();
String sql = "SELECT ID,CategoryName from Category";
cmd = new SqlCommand(sql, con);
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dataGridViewX1.Rows.Clear();
while (rdr.Read() == true)
{
    dataGridViewX1.Rows.Add(rdr[0], rdr[1]);
}

Why i can't use like this way in the real world application?

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • 1
    You can use ADO.NET and many still do. But using an ORM layer like Entity Framework has many advantages. A micro-ORM that is very close to ADO.NET is [Dapper.Net](https://github.com/StackExchange/Dapper). Have a look – Tim Schmelter Nov 15 '18 at 17:20
  • Possible duplicate of [What is the difference between an orm and ADO.net?](https://stackoverflow.com/questions/40506382/what-is-the-difference-between-an-orm-and-ado-net) – Igor Nov 15 '18 at 18:33
  • Possible duplicate of [Traditional sql approach VS ORM](https://stackoverflow.com/q/31940160/1260204) – Igor Nov 15 '18 at 18:34

1 Answers1

0

Tim is right. There is nothing stopping you from using ADO.Net. There are some advantages to using an ORM. A major advantage from a security perspective is that ORM queries that have some kind of where clause are not vulnerable to SQL injection since they are translated into parameterized queries.

James
  • 168
  • 8