在Asp.Net MVC应用程序编程方式创建新的数据库? [英] Create new database programmatically in Asp.Net MVC application?

查看:120
本文介绍了在Asp.Net MVC应用程序编程方式创建新的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC 2上的时间表应用程序的应用程序工作在公司内部使用。现在,其他小公司都表现出了兴趣的应用。我没有考虑过这个应用程序的使用,但它让我感兴趣的是它可能暗示。

I have worked on a timesheet application application in MVC 2 for internal use in our company. Now other small companies have showed interest in the application. I hadn't considered this use of the application, but it got me interested in what it might imply.

我相信我可以使它通过修改数据库(SQL Server通过实体框架模型访问)为多个客户工作。但我看过一些人崇尚多个数据库(每个客户端)。

I believe I could make it work for several clients by modifying the database (Sql Server accessed by Entity Framework model). But I have read some people advocating multiple databases (one for each client).

直观地说,这种感觉就像是个好主意,因为我不会冒险让在同一数据库中混淆了不同客户的数据(这不应该发生的,当然,但如果它的所作所为......)。但如何将多个数据库解决方案,具体实施的?

Intuitively, this feels like a good idea, since I wouldn't risk having the data of various clients mixed up in the same database (which shouldn't happen of course, but what if it did...). But how would a multiple database solution be implemented specifically?

即。与单个数据库我可以有一个客户寄存器和所有必要的数据将通过应用程序被添加以同样的方式,现在是时候这里只有一个客户端(我自己的公司)。

I.e. with a single database I could just have a client register and all the data needed would be added by the application the same way it is now when there's just one client (my own company).

但随着多个数据库的解决方案,我将如何编程方式创建一个新的数据库,当用户登记?请注意,我已经做了使用LINQ到SQL数据库的所有的东西,我不是很熟悉规则SQL编程...

But with a multiple database solution, how would I create a new database programmatically when a user registers? Please note that I have done all database stuff using Linq to Sql, and I am not very familiar with regular SQL programming...

我真的AP preciate怎么可以这样做一个明确详细的解释(以及它是否是一个好主意,或者一个单独的数据库会因为某些原因更好的输入)。

I would really appreciate a clear detailed explanation of how this could be done (as well as input on whether it is a good idea or if a single database would be better for some reason).

编辑:

我也看到了有关单一数据库替代的讨论,这表明你会再添加客户端Id为每个表......但是那不是很难在code来维持?我会,其中条件增加了很多的LINQ查询我承担......而我认为有每桌一个clientId意味着每个表中将需要有一个多对一的关系,以客户表?那不是一个非常复杂的数据库结构?

I have also seen discussions about the single database alternative, suggesting that you would then add ClientId to each table... But wouldn't that be hard to maintain in the code? I would have to add "where" conditions to a lot of linq queries I assume... And I assume having a ClientId on each table would mean that each table would have need to have a many to one relationship to the Client table? Wouldn't that be a very complex database structure?

由于它是现在(未经客户表)我有以下表(1 - > *指定一对多的关系):

As it is right now (without the Client table) I have the following tables (1 -> * designates one to many relationship):

1号客户 - > *项目1 - > *任务1 - > * TimeSeg​​ment 1 - > *员工

Customer 1 -> * Project 1 -> * Task 1 -> * TimeSegment 1 -> * Employee

此外,客户有一个人跟TimeSeg​​ment直接一对多的关系,为方便起见,以简化一些查询。

Also, Customer has a one to many relationship directly with TimeSegment, for convenience to simplify some queries.

这至今工作非常出色。那岂不是可以简单地有一个客户表(或UserCompany或任何人们可以称呼它)有一个与客户表中的许多关系?不会由于其余由关系处理的数据完整性足以使得其他表

This has worked very well so far. Wouldn't it be possible to simply have a Client table (or UserCompany or whatever one might call it) with a one to many relationship with Customer table? Wouldn't the data integrity be sufficient for the other tables since the rest is handled by the relationships?

推荐答案

至于是否要使用一个或多个数据库,这真的一切都取决于用例。更多的数据库意味着更多的管理需求,可能更需要的磁盘空间,等等还有很多更多的东西在这里不仅仅是考虑如何创建数据库,比如你将如何实现自动化备份过程的创建,等等。我个人会使用一个数据库一个良好的认证系统,将筛选数据到相应的客户端。

as far as whether or not to use a single database or multiple databases, it really all depends on the use cases. more databases means more management needs, potentially more diskspace needs, etc. there are alot more things to consider here than just how to create the database, such as how will you automate the backup process creation, etc. i personally would use one database with a good authentication system that would filter the data to the appropriate client.

为创建数据库,请查看这个博客帖子。它介绍了如何使用SMO(SQL管理对象)在C#.NET创建一个数据库。他们是一个非常整洁的工具,你一定会要熟悉它们。

as to creating a database, check out this blog post. it describes how to use SMO (sql management objects) in c#.net to create a database. they are a really neat tool, and you'll definitely want to familiarize yourself with them.

要处理后续问题,是的,客户和客户之间的一个单一的,顶级的关系应该是足够的新客户限制其相应的数据。

to deal with the follow up question, yes, a single, top level relationship between clients and customers should be enough to limit the new customers to their appropriate data.

无关于你的应用程序的任何真正的知识我不能说有多复杂并称表会,但假设你的数据层是及格,我会假设你真的只需要通过电流限制类客户客户端,然后获得基于可用的客户数据的所有的休息。

without any real knowledge about your application i can't say how complex adding that table will be, but assuming your data layer is up to snuff, i would assume you'd really only need to limit the customers class by the current client, and then get all the rest of your data based on the customers that are available.

这样做有什么意义?

这篇关于在Asp.Net MVC应用程序编程方式创建新的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆