通过程序集访问数据库的正确方法是什么?

发布于 2024-08-27 11:43:53 字数 239 浏览 3 评论 0原文

我有一个 ASP.NET MVC 应用程序,它构建为一个查询数据库的程序集和一个引用该程序集的 asp.net 前端,并且该程序集抽象了底层数据库。这意味着我的程序集包含一个 app.config 文件,其中包含数据库的连接字符串(Linq to SQL 数据模型)。我该如何使其更加灵活?我是否应该在程序集中的某个位置创建一个“initialize()”方法,该方法从 asp.net MVC 应用程序获取连接字符串,然后控制要使用的数据库?或者这是如何完成的?

I have a ASP.NET MVC application which is build up as an assembly that queries the database and a asp.net frontend that references this assembly and this assembly abstracts the underlying database. This means that my Assembly contains a app.config file that contains the connectionstring to the database (Linq to SQL data model). How do I go about making this more flexible? Should I make a "initialize()" method somewhere in my assembly which takes the connection string from the asp.net MVC application and then that controls which database to use? or how is this done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若沐 2024-09-03 11:43:53

您可以在项目属性中为该程序集创建设置。但是,您确实不应该像这样静态配置内容。应该可以从程序集中创建两个对象系统,每个系统都指向不同的数据库,而不会影响另一个系统。

You can create a setting for that assembly in the project properties. However, you really shouldn't have things configured statically like that. It should be possible to create two systems of objects from your assembly that each point toward a different database without either affecting the other.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文