什么决定了 EF Code First 的 SQL Azure 数据库版本和大小?

发布于 2025-01-07 18:29:53 字数 253 浏览 4 评论 0原文

我有一个 POC 解决方案,它使用 ASP.NET MVC 3 创建网站,并使用 Entity Framework 4.3 Code First 方法进行数据访问。我能够部署到 Azure 中的托管服务,并根据我的连接字符串在 SQL Azure 中创建我的数据库。我不明白的是数据库版本(Web)和大小(1GB)是如何确定的。这只是默认设置还是可以控制的?

我可能计划通过在投入生产时将数据库初始值设定项设置为 null 来解决此问题,并自行管理它,但我想了解这些选项。谢谢

I have a POC solution that uses an ASP.NET MVC 3 to create a web site and Entity Framework 4.3 Code First approach for the data access. I am able to deploy to a hosted service in Azure and my database gets created in SQL Azure based on my connection string. What I don't understand is how the database edition (Web) and size (1GB) were determined. Is this just the default or is it controllable?

I may plan to approach this by setting my database initializer to null when going to production and manage that on my own anyway, but I want to understand the options. Thanks

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

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

发布评论

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

评论(2

£噩梦荏苒 2025-01-14 18:29:53

您可以在 CREATE DATABASE 调用中指定版本和最大大小。如果省略了 version 和 maxsize 参数,则默认为 Web,1GB。完整的 CREATE DATABASE 调用是:

CREATE DATABASE database_name  [ COLLATE collation_name ]
{
   (<edition_options> [, ...n]) 
}

<edition_options> ::= 
{
   (MAXSIZE = {1 | 5 | 10 | 20 | 30 … 150} GB) 
    |(EDITION = {'web' | 'business'})
}

请参阅此 MSDN参考页面了解更多详情。

You can specify edition and max size in the CREATE DATABASE call. If the edition and maxsize parameters are omitted, the default is Web, 1GB. The full CREATE DATABASE call is:

CREATE DATABASE database_name  [ COLLATE collation_name ]
{
   (<edition_options> [, ...n]) 
}

<edition_options> ::= 
{
   (MAXSIZE = {1 | 5 | 10 | 20 | 30 … 150} GB) 
    |(EDITION = {'web' | 'business'})
}

See this MSDN reference page for more details.

长发绾君心 2025-01-14 18:29:53

您可以使用以下一种常见解决方案:

选项一:您可以在创建 Azure 数据库后更改其层

我讨厌这个解决方案,因为 (1) 您总是会忘记从时不时地。 (2) 这意味着您必须在数据库创建后等待更多时间才能开始工作。 (3) 如果你不能指望它并且需要自己管理数据库,那么使用 ORM 有何意义?!?

选项二:您始终可以使用直接查询提前创建数据库

如果您确实想使用像 EF 这样的 ORM,那么在大多数情况下这是我的首选选项。同样,缺点是您需要自己管理数据库,并且需要知道如何编写查询而不仅仅是使用 ORM。

您可以在应用程序中使用实体框架方法“SqlCommand.ExecuteNonQuery”来执行此操作。事实上这是一个必须知道的方法。

专家将 EF 用于复杂系统的方式基于通过我们自己编写直接查询来绕过 ORM 不良解决方案的能力。这意味着“将 EF 与纯查询和数据库管理相结合”。

例如:

var Query2CreateDB = $"CREATE DATABASE RonenArielyDB2(EDITION = 'Basic', SERVICE_OBJECTIVE = 'Basic',MAXSIZE = 100 MB);";
ExecuteNonQuery(connectionString, Query2CreateDB, commandTimeout: 600);

这就是为什么在使用实体框架或任何其他 ORM 之前,您必须首先学习如何编写查询并使用查询管理数据库!

选项三:创建您自己的自定义 EF 初始值设定项(覆盖内置类)

对于想要依赖实体框架等纯 ORM 解决方案的开发人员来说,这是最佳解决方案!

下面的帖子中有一个很好的例子!
https://blog.siliconvalve.com/2014/11/12/use-azure-management-api-sdk-in-an-entity-framework-custom-database-initializer/

选择您的解决方案

You can use one ope the following Common solutions:

Option one: You can change the tier of the Azure Database after it has been created

I hate this solution since (1) you will always forget to do it from time to time. (2) This mean that you must wait more time after the database was created before you start your work. (3) What is the meaning of using ORM if you cannot count on it and you will need to manage the database yourself?!?

Option two:You can always create the database in advance using direct queries

This is my preferred option for most cases, if you really want to work with ORM like EF. Again the disadvantage is that you manage the database yourself and you need to know to write the queries and not just using the ORM.

You can do this in your application using Entity Framework method "SqlCommand.ExecuteNonQuery". in fact THIS IS A MUST TO KNOW METHOD.

The way experts can use EF for complex system based on the ability to bypass the ORM bad solutions by writing direct queries ourselves. This means "combine EF with pure queries and database management".

For example:

var Query2CreateDB = $"CREATE DATABASE RonenArielyDB2(EDITION = 'Basic', SERVICE_OBJECTIVE = 'Basic',MAXSIZE = 100 MB);";
ExecuteNonQuery(connectionString, Query2CreateDB, commandTimeout: 600);

And this is why you must first learn how to write queries and manage the database using queries BEFORE you use Entity Framework or any other ORM!

Option three: Create you own custom EF initializer (override the build-in class)

THIS IS THE BEST SOLUTION FOR DEVELOPERS who want to count on pure ORM solutions like Entity Framework!

There is a great example in the following post!
https://blog.siliconvalve.com/2014/11/12/use-azure-management-api-sdk-in-an-entity-framework-custom-database-initializer/

Choose you solution ????

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