0

I'm learning ASP.NET Core 2, with Entity Framework Core. A real use-case scenario is a small management of a production process. I have some persistent table like customers, orders, machines, etc... but I also have some "live" tables.

Example: the current status of the machines. This information is valid only at the present moment. Every, say 1 second, I will get new updated information about the machine's status.

To show these values on a web page (Razor) is very useful to define a Model. But due to the very high refresh rate, I'm not sure storing them in a regular database is the best idea. Furthermore on startup I must delete all data because I need to receive the actual one.

Hence, I think a "in-memory" database could be a solution, but the official documentation seems to discourage this practice:

The InMemory provider is useful when you want to test components using something that approximates connecting to the real database, without the overhead of actual database operations.

Am I interpreting correctly the above sentence? Or they just propose ONE of the possible use of such a database?

  • what is the advantage over a List? – Ewan Nov 25 '17 at 10:38
  • Because I'm learning, I'm able to query and view data in a DbSet. Hence I cannot say what are the advantages over a List. i'm going to look into it. Thanks. – Mark Nov 25 '17 at 11:27
  • Another point is to use the same objects for both persistent and live data, so if in the future I need to make it persistent I just have to change DbContext. – Mark Nov 25 '17 at 11:29
  • 1
    well the short answer is "no". it will be faster just to hold the list of models in the applications memory – Ewan Nov 25 '17 at 11:44
  • Got it. I've already changed my code to use a List<>. – Mark Nov 25 '17 at 13:40
1

I wouldn't indulge in the InMemoryDatabase. You do not have a need to do that. You are already creating objects that hold the status of the machines in memory. Just use those in your view. All you need is to populate appropriate Model objects when the new status of machines is read and use in your view.

That will keep it simple. Adding an InMemoryDatabase seems unnecessary complexity, and unless there is a reason not mentioned in the question, I would not even put any energy in doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.