SQL Server + Entity Framework basics

14,836

Solution 1

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

Solution 2

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=en which 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.

Solution 3

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.

Share:
14,836

Related videos on Youtube

Demolition Chico
Author by

Demolition Chico

Updated on September 14, 2022

Comments

  • Demolition Chico
    Demolition Chico over 1 year

    I have this task to create a program in C# for managing company's staff. Only a brief overview - all the information about each employee is to be stored in MS SQL database. As a presentation layer, I have to use WPF and as a communication with database - LINQ to Entities.

    The thing is - I managed to learn WPF on my own, but SQL is a serious matter. I've done some research, but even after reading many different tutorials I haven't found anything satisfying. I don't even understand the mechanics of this model. 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. I may be wrong, and that is highly probable, but I just don't get it.

    So, can anyone point me to a right direction? What do I even have to know to start? Maybe some tutorials for such a noob?

  • Demolition Chico
    Demolition Chico over 10 years
    My mistake was assuming that Enity framework connects to a file. Understanding that it connects to an engine helped a lot. Thank You :)
  • markmnl
    markmnl over 7 years
    You can send raw SQL still