SQL Server + Entity Framework basics SQL Server + Entity Framework basics database database

SQL Server + Entity Framework basics


ADO.NET Entity Framework (EF) was first released with Visual Studio 2008 and .NET Framework 3.5 Service Pack 1. So far, many people view EF as just another ORM product from Microsoft, though by design it is supposed to be much more powerful than just an ORM tool.A new data-access provider, EntityClient, is created for this new framework but under the hood, the ADO.NET data providers are still being used to communicate with the databases

The application no longer connects directly to a database or sees any database-specific construct; the entire application operates in terms of the higher-level EDM model.This means that you can no longer use the native database query language; not only will the database not understand the EDM model, but also current database query languages do not have the constructs required to deal with the elements introduced by the EDM such as inheritance, relationships, complex-types, etc.

. LINQ to Entities allows developers to create flexible, strongly typed queries against the Entity Data Model (EDM) by using LINQ expressions and the LINQ standard query operators

Tutorial can be Found Here


It's basically the opposite of what you said actually:

It is my understanding, that creating a database in SQL Server simply does nothing, because after one creates Entity model from the database, it is no longer tied to SQL Server. So updating data in created SQL database is no longer of use to the program itself.

What happens is the Entity Framework (EF) connects to your database and gets the data from your SQL Server. From then, when you make changes in your app, EF operates in 'detached' sort of mode. This is probably the source of your confusion. The piece you are missing, is that you tell EF using ef.SaveChanges() to push all of the changes made in 'detached' mode, back to your database. So you make your changes in memory, then when you are ready, you tell EF to push those changes to the database.

Now to your other point, if you make a change directly to SQL Server (which I could see scenarios where this would occur), you certainly would run into issues with your 'detached' mode EF objects. I'm honestly not sure what would happen here, someone more experienced than me should say, that's a really interesting question that I'd also like to know the answer to.

Here are some tutorial infos that I found that seemed good:

http://www.microsoft.com/downloads/details.aspx?FamilyID=355c80e9-fde0-4812-98b5-8a03f5874e96&displaylang=enwhich is actually in this answer

and also:

http://www.codeproject.com/Articles/363040/An-Introduction-to-Entity-Framework-for-Absolute-B

EDIT: when I talk about detached mode, understand that inside EF there are various modes that you can operate in, one of which is detached mode. I hated to use the term 'detatched mode' in my answer b/c I know others will come along and say that term is confusing, and they are correct. Just understand that inside EF there is a 'detatched' mode and it is somewhat of an advanced topic.


Entity Framework is very easy and very powerful ORM. My suggestion to you would be to start with http://www.asp.net/entity-framework. Here you can find a lot of Get Started tutorials to help you up and running in a short time. Although these tutorials are tied with ASP.NET, you can very easily understand them and use them with other platforms.