C#使用多个应用程序使用Entity Framework连接单个数据库

时间:2022-03-10 00:39:17

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.

我目前正在开发一个Windows表单应用程序,我打算在云设置上运行,应用程序将计算新数据,在数据库中更新,并充当我希望使用的实时数据源RestFul API的一种控制面板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 * 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?

有更好的解决方案吗?我应该废弃运行Windows窗体应用程序来控制公共API后端的某些元素的想法吗?

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

设计这样的东西会有什么未来的问题,如果有的话?

2 个解决方案

#1


2  

Create a Data access layer, as a seperate component.

创建数据访问层,作为单独的组件。

like a DAL.dll

像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.

每个层现在都使用一种Interfacelayer,它将对象从应用程序的任一层转换为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.

如果你想要更多的细节,我需要来自程序和SQL表设计的类的例子。

But there is nothing wrong with your approach.

但是你的方法没有错。

#2


2  

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

假设你有一个分层架构,那么你有很多选择:

  1. Share your DB, DAL and also Business Layer
  2. 分享您的数据库,DAL和业务层
  3. Extend your WEB API and utilize it in your WinForms
  4. 扩展您的WEB API并在WinForms中使用它
  5. Reuse DAL only (not the best approach, as business systems are not only data, but also - behavior - which resides in Business Layer)
  6. 仅重用DAL(不是最好的方法,因为业务系统不仅是数据,而且 - 行为 - 驻留在业务层中)
  7. Share the DB only - this is the worst option, with numerous drawbacks
  8. 仅分享数据库 - 这是最糟糕的选择,有许多缺点

See options 1 and 2 on an image:

请参阅图像上的选项1和2:

C#使用多个应用程序使用Entity Framework连接单个数据库 C#使用多个应用程序使用Entity Framework连接单个数据库

#1


2  

Create a Data access layer, as a seperate component.

创建数据访问层,作为单独的组件。

like a DAL.dll

像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.

每个层现在都使用一种Interfacelayer,它将对象从应用程序的任一层转换为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.

如果你想要更多的细节,我需要来自程序和SQL表设计的类的例子。

But there is nothing wrong with your approach.

但是你的方法没有错。

#2


2  

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

假设你有一个分层架构,那么你有很多选择:

  1. Share your DB, DAL and also Business Layer
  2. 分享您的数据库,DAL和业务层
  3. Extend your WEB API and utilize it in your WinForms
  4. 扩展您的WEB API并在WinForms中使用它
  5. Reuse DAL only (not the best approach, as business systems are not only data, but also - behavior - which resides in Business Layer)
  6. 仅重用DAL(不是最好的方法,因为业务系统不仅是数据,而且 - 行为 - 驻留在业务层中)
  7. Share the DB only - this is the worst option, with numerous drawbacks
  8. 仅分享数据库 - 这是最糟糕的选择,有许多缺点

See options 1 and 2 on an image:

请参阅图像上的选项1和2:

C#使用多个应用程序使用Entity Framework连接单个数据库 C#使用多个应用程序使用Entity Framework连接单个数据库