Corona
Corona

Reputation: 374

C# Using multiple applications to connect a single database using Entity Framework

I am currently developing a Windows form application, that I plan to run on a cloud setup, the application will calculate new data, update within the database and act as sort of control panel for a live data feed RestFul API that I wish to create using ASP.NET MVC 5 Web API.

I am wondering is it viable to connect these 2 separate applications to a single database? It is unlikely that I'd have database entry clash issues as each application has a separate task of reading or writing data for certain tables.

If viable would that mean every-time i make table changes I'd have to update both Entity Framework database models? (Not a major chore).

Is there a better solution to this? Should I scrap the idea of running a Windows Form application to control certain elements of the backend of the public API?

What would be the future issues with designing something like this, if any?

Upvotes: 3

Views: 3672

Answers (2)

ironstone13
ironstone13

Reputation: 3443

So you have a bunch of options there, assuming you have a layered architecture:

  1. Share your DB, DAL and also Business Layer
  2. Extend your WEB API and utilize it in your WinForms
  3. Reuse DAL only (not the best approach, as business systems are not only data, but also - behavior - which resides in Business Layer)
  4. Share the DB only - this is the worst option, with numerous drawbacks

See options 1 and 2 on an image:

enter image description here enter image description here

Upvotes: 3

Morten Bork
Morten Bork

Reputation: 1632

Create a Data access layer, as a seperate component.

like a DAL.dll

Each application has a Logic layer, where "whatever you do" is handled.

Each layer, now uses a sort of Interfacelayer, that will translate objects from either layer of your applications, to the objects of the DAL.

When you change the DB now - you merely have to update the interface layer.

(Of course if you are adding more features, you will have to update all layers, but that isn't really any different.

I suggest this appoach, as it will make your debugging task much easier. And the slight extra code overhead won't affect performance, unless you have a massive communication requirement.

If you want more specifics, I would need examples of a classes from either program, and your SQL table design.

But there is nothing wrong with your approach.

Upvotes: 2

Related Questions