ADO.NET vs EntityFramework - c#

Can someone please explain the difference between ADO.NET and Entity Framework in layman's terms?
I have searched from Google but can't understand the difference.
ADO.Net means using sqlConnection();, sqlCommand(); etc. to interact with database using queries?
Entity Framework means using db.Add();, db.SaveChanges(); functions to interact with database without using queries? Am I right?

When you use EF db.Add(); or db.SaveChanges or any other integrated EF method, the ORM (object-relational mapper), in this example EF, will use ADO.NET (so EF will open database connection using ADO.NET, EF will create "SQL query" using ADO.NET,...).
Of course, you can do this all by yourself, using ADO.NET methods, which sometimes can increase the performance of the queries, but usually needs more code writing.
But in general, when you use EF, you also use ADO.NET, only its implemented inside EF methods.

Related

asp.net mvc c# with sql without ORM

So I have to make a asp.net project with SQL Server database, the problem is that I have to do it without any ORM-with a specific DB controller and I have always used the Entity Framework which IS an ORM.
I have no idea from where to begin. How do I collect the data and send it the controller with the html.helpers and how to structure the db controller?
I am not allowed to use Linq either just SQL. As much as I can see from the others questions I should use the SQL command class but its not explained structurally.
What I am asking here is just for the basics.How do I get it from the html helper to the database without ORM and what will I need for that as clases and models,how to relate them and if possible for a simple example.
As you mentioned, you can use "classic" SQL commands with ADO.NET. Here is a good example:
Using ASP.Net MVC with Classic ADO.Net
Another way, and in my opinion a very fast and convenient way, is to use the Dapper framework.
I would recommend you to use Dapper with Stored Procedures. It's a good trade-off between ORM (like Entity Framework) and classical SQL commands. I can show you an example if you give me a business case.

Difference between Native SQL and Entity SQL

I have gone through an article of using EntityConnection, EntityCommands for executing Entity sql queries. But I was unable to understand that Why are we using Entity sql? Why not directly using the Classes and objects for processing CRUD operations on database?
Or If we want to execute sql queries then why we are using Entity Sql , why not directly Ado.net ?
Is there any performance difference or something else?
I have already gone through the page http://msdn.microsoft.com/en-us/library/bb738573.aspx. But I want answer in a more simpler way. Can you please answer me?
Thanks
Why not directly using the Classes and objects for processing CRUD operations on database?
That is (should be) the way for almost all operations. But sometimes there is a need for accessing the db more directly and precisely.
If we want to execute sql queries then why we are using Entity Sql , why not directly Ado.net ?
E-SQL will still let you work with entities (instead of Rows). This is much easier and more powerful, consider inheritance for example.
E-SQL is also supposed to be independent of the actual database, ie the same for Oracle etc. I have no experience with this yet.
Is there any performance difference or something else?
It can be used to improve performance, yes. But not automatically.
The main difference
SQL is database dependent query language working on storage (relational) objects - tables / rows
ESQL is database independent query language working on conceptual (EDMX) objects - entities
ESQL was created prior to LINQ. In some scenarios ESQL offers more functionality than LINQ.

How to connect to a MySQL database inside the .NET framework?

I'm opening a discussion here on a subject I couldn't find any answer good enough to be called a final answer: MySQL and .NET.
While I know there is a lot of ways to make this connection, I'm trying to find a list of pros and cons of each approach.
I've been using ADO.NET with the MySQL NETconnector since the beggining of my project, and everything was ok when the database was new and didn't have many records. But now I'm facing a situation where the number of records grows exponentially, and I found other way of querying against the database, which is the ODBC connector. Using the ADO.NET + NETConnector solution I had my O/RM and didn't have to write my queries, while ODBC makes my code look awful now (since I didn't switch completely to ODBC, I have Linq queries and plain SQL queries inside my code).
Is there any solution (free or not) where I can have both an O/RM without the need of writing SQL queries myself and the speed of ODBC?
What you should be doing is using the MySQL ADO.NET Connector and storing your queries in the database in the form of stored procedures. Version 6.0 of the MySQL connector also supports The Entity Framework. If you are interested in using the Entity Framework, check out this link which describes how to set that up.
NHibernate
Update to Comments
NHibernate Proxy Generators
It is a byte code generator for your object model that allows NHibernate to perform lazy loading and other operations. The link provided explains the benefits.
Castle and LinFu are two different implementations of those Proxy Generators.
While NHibernate does not have coincide documentation all the information on how to use it, is on the internet. This could be a barrier to usability for some people though. I understand more about NHibernate because of my past experience with Hibernate.

Entity framework run direct query

I'm thinking about using Entity Framework in an ASP.NET application, using an Oracle database.
I would also need to know is I can run a query directly on the database tables and data, using Entity Framework, without using the classes and the mappings.
Thanks!
ExecuteStoreQuery can be used.
However, part of the beauty/fun/elegance of using Entity is being able to write your queries using LINQ and not having to write actual SQL statements.
Also, just because you decide to use Entity, doesn't mean you can no longer use SqlCommand objects etc...
You could use ExecuteStoreQuery() for that. Be aware though that you a have to provide a type that all returned columns can be mapped to, it does not have to be an entity though.

Is it possible to set the actual SQL that the entity framework provider will execute?

My entity framework provider (CoreLabs/Mysql/devart) is creating ridiculously slow queries.
is it possible for me to set the actual sql query that will be executed?
Thanks
its funny, i was just watching LINQPad - New Features for Entity Framework. half way through the webcast, he showed the script generated by the EF and the same query generated by Linq-To-Sql; the linq-to-sql generated script was way more efficient. Now i don't know if using linq-to-sql is an option for you but i thought you should know,
in regards to your question, as i understand the whole point of EF and Linq-to-sql to avoid programmers writing TSQL in strings, doesn't force feeding your own SQL command kind of defeat the whole purpose of EF and Linq-to-sql?
Yes, one way is with the ObjectQuery.ToTraceString API.

Categories