通过程序集访问数据库的正确方法是什么?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在项目属性中为该程序集创建设置。但是,您确实不应该像这样静态配置内容。应该可以从程序集中创建两个对象系统,每个系统都指向不同的数据库,而不会影响另一个系统。
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.