1

I want to know if Entity Framework should be used in a connected or disconnected architecture?

Specially, I want to know how I can use EF in a layered architecture. For example how can I use it in ASP.NET code behind?

NOTE: There are requests for closing this question as "Primarily opinion-based" and this is clearly not the case: EF can be used in both kind of scenaraios in a very specific way. That's not an opinion, but a clear fact. Noone can discuss it, or agree or disagree. If the question was about how to implement a disconnected scenario, then it would become "opinion-based", but not as is stated right now.

JotaBe
  • 38,030
  • 8
  • 98
  • 117
Dilip Oganiya
  • 1,504
  • 12
  • 20
  • May i know why i am upvoted ? Please give me reason for that – Dilip Oganiya Dec 16 '15 at 09:27
  • Actually you were downvoted. If you want to know the reason please read this: http://stackoverflow.com/help/mcve – チーズパン Dec 16 '15 at 09:31
  • Yes but i dont know why i am downvoted. – Dilip Oganiya Dec 16 '15 at 09:37
  • You can read it up in the link I posted. But actually you were downvoted because of several reasons. Your quetion is not really clear. You also do not provide any of your own effort on researching the topic... – チーズパン Dec 16 '15 at 09:41
  • @Käsebrot, with all my respect, you shouldn't be so dogmatic. There are many "not code-centric" questions that can be answered without incurring in the `too broad` or `unclerar what you asking` or `primarily opinion based` whichever other reason to downvote and close it. I think this is one of this cases. I mark may questions for closing, but I think this one doesn't deserve it. If you don't undertsnad the question, or any other thing, it's much better to help the OP clarify it. – JotaBe Dec 16 '15 at 09:45
  • Just to be clear pal, I did not downvote your question. – チーズパン Dec 16 '15 at 09:56

1 Answers1

2

You can use EF in both scenarios.

In a connected scenario, you can keep an instance of DbContext while you make changes to the entities (add, delete, update, modify), so that it tracks the cahnges and automatically send them to the database when calling SaveChanges.

In a disconnected scenario, for example a web application, you're responsible of tracking the changes. When you get the data back to the server you need to instance a new DbContext, attach the entities to it, set the state of each entity (new, deleted, modified), and call SaveChanges. For more information you can read this.

So, EF supports both scenarios, but in a different way.

JotaBe
  • 38,030
  • 8
  • 98
  • 117
  • Which is better? I guess the former in your discussion. – azure boy Jan 18 '19 at 12:52
  • There is no best option. They are simply different. In the case of disconnected applications, like a web app, you have no choice. In a desktop application you can choose one of the two options. This question is like asking, which is better travelling by train or by bus? – JotaBe Jan 18 '19 at 15:43