如果不能安全地在生产中使用实体框架代码,为什么还应该使用它,而无法描述索引之类的内容

时间:2022-05-02 01:21:06

I'm just starting out an extremely large web project, and really trying to do everything right.

我刚刚开始一个非常大的网络项目,并且真的想要做正确的事情。

My tools using so far are

到目前为止我使用的工具是

  • ASP.NET MVC 3
  • ASP.NET MVC 3
  • Entity Framework 4.3
  • 实体框架4.3
  • Ninject 3
  • Ninject 3

All is going well, but I'm finding a few things with Entity Framework CodeFirst a bit sketchy.

一切进展顺利,但我发现Entity Framework CodeFirst的一些内容有点粗略。

For example, I had to use http://codefirstmembership.codeplex.com/ to setup membership information as part of the code first setup. This feels a bit ropey to have to use something third party of this. Obviously I should be 1337 enough to "roll my own" but I don't want to bite off too much from the get go. Running aspnet_regsql feels horrible, and will get lost with each db update. Anyway, got it all working with the above library and it's not too bad. Scaffolding seems to have broken however.

例如,我必须使用http://codefirstmembership.codeplex.com/来设置成员资格信息,作为代码首次设置的一部分。不得不使用第三方这一点,这感觉有点啰嗦。显然我应该足够1337“自己动手”,但我不想在开始时咬掉太多东西。运行aspnet_regsql感觉很糟糕,每次db更新都会丢失。无论如何,让这一切都与上面的库一起工作,这不是太糟糕。然而,脚手架似乎已经破裂。

Now beyond all this, it now seems that this stuff is going to become probamatic when I am running in the live environment. Any schema changes I'm going to want to make between the dev db and live db will have to be manually managed with scripts anyway, so at that point am I not losing the point of code first?

现在,除此之外,现在看来,当我在现场环境中运行时,这些东西将成为问题。我想要在dev db和live db之间进行的任何模式更改都必须使用脚本手动管理,所以在这一点上我不会先丢失代码点吗?

I've been working with Google App Engine for the last year, and was hoping that code first would essentially work in the same way? Ie, make changes and they modify the live data. Now I assume, due to not having done severe refactoring in app engine, that it basically doesn't harm anything in production. So you could never rename a table with AppEngine. It would always create a new table, and leave the old one. You would have to manually port data.

去年我一直在使用谷歌应用引擎,并希望代码首先基本上以同样的方式工作?即,进行更改并修改实时数据。现在我假设,由于没有在app引擎中进行过严格的重构,它基本上不会对生产中的任何东西造成伤害。因此,您永远无法使用AppEngine重命名表。它总是会创建一个新表,而保留旧表。您必须手动移植数据。

So I'm now thinking. Why not just go Database first? I've been working with linq2sql for 3 years and very comfortable with going db first. Although TBH my db source control stratergy has been a little....lacking. So I was hoping code first would enforce that situation to improve, but it actually makes me feel that I should go DB first, and just be strict about keeping it under control.

所以我现在在想。为什么不先去数据库呢?我已经使用linq2sql工作了3年,并且非常适合首先使用db。虽然TBH我的数据库源控制策略已经有点......缺乏。所以我希望代码能够首先强制执行这种情况,但它实际上让我觉得我应该首先使用DB,并且要严格控制它。

I would really appreciate any thoughts on this kind of situation, and also, how does this compare to using Nhibinate?

我真的很感激对这种情况的任何想法,而且,这与使用Nhibinate相比如何?

2 个解决方案

#1


7  

The upgrade scenario's you're describing are being added in EF-Migrations. The go-live release of this is already available and it should become available as a officially supported release version soon.

您正在描述的升级方案正在EF-Migrations中添加。该产品的上线版本已经发布,它很快就会作为官方支持的版本提供。

Check out: https://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx?Redirected=true

退房:https://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx?Redirected = true

Check out: http://coding.abel.nu/tag/ef-migrations/

查看:http://coding.abel.nu/tag/ef-migrations/

#2


3  

Just my take on this...

只是我对此的看法......

You don't need to make a choice for good -

你不需要做出好的选择 -

you can use Seed, custom initializer (and migrations hand in hand - with migrations you can actually manually change them, e.g. add indexes there etc. - though carefully), to 'inject' the raw SQL (and most of the needs could be covered by that). As far as I know you could run a custom batch file form initializer (but haven't tried, though I don't see why not). Migrations are done through PS so I'm guessing there is space to integrate on that side too.

您可以使用种子,自定义初始化程序(和迁移一起进行迁移 - 您可以实际手动更改它们,例如在那里添加索引等 - 尽管小心),“注入”原始SQL(并且可以涵盖大部分需求)那个)。据我所知,你可以运行自定义批处理文件表单初始化程序(但没有尝试,但我不明白为什么不)。迁移是通过PS完成的,所以我猜这个方面也有空间集成。

You can use it to prototype things and startup - get your C# structure in place and in sync fast - then shape it up later - or once fixed use some 'use existing initializer' which does nothing from the code and move everything to Db side and your DBA.

您可以使用它来原型化和启动 - 让您的C#结构就位并快速同步 - 然后再将其整形 - 或者一旦修复使用一些'使用现有的初始化程序',它不会对代码执行任何操作并将所有内容移动到Db端并且你的DBA。

IMO, you can go 'very far' in this sense, before actually needing to turn CF off and just work from Db.

IMO,你可以在这个意义上“走得很远”,然后才真正需要关闭CF并从Db开始工作。

For larger databases, or corporate environments, it's definitely not the right tool for the job.

对于较大的数据库或企业环境,它绝对不是适合这项工作的工具。

I think it's now safe for production - but depends on what you consider safe, few things...

我认为它现在可以安全生产 - 但取决于你认为安全的东西,很少的东西......

Also, EF/CF has gone a long way since the beginnings really - I used it since the start - and it had big problems initially. The latest versions are now pretty solid on all sides, so it's getting there I think.

此外,EF / CF从一开始就走了很长的路 - 我从一开始就使用它 - 而且它最初有很大的问题。最新版本现在各方面都很稳固,所以我认为它已经到了那里。

...on the downside - I had worked out some pretty complex scenarios with code first approach (EF and otherwise). However, few things held me back with EF (on top of what you mentioned)...

......在不利方面 - 我用代码优先方法(EF和其他方法)制定了一些相当复杂的场景。然而,很少有东西让我回到EF(在你提到的之上)......

UDF support, views (with linq - as if you're not to use LINQ one of the big 'pros' is gone) - which should come up in EF 5.0 (I did not check but it's what they're promissing) - as for more complex scenarios you need to optimize on the SQL side (or to be able to execute custom queries on the back and then map back, i.e. more flexibility on that side). So that's a promising thing if it comes (though won't be perfect I expect). (on the plus side, you can actually run custom queries and then map to your objects - but that sort of works, and you cannot do everything so it's limited in a way)

UDF支持,观点(使用linq - 就好像你不使用LINQ的一个大'专业'已经不见了 - 这应该出现在EF 5.0中(我没有检查,但这是他们的承诺) - 如对于更复杂的场景,您需要在SQL端进行优化(或者能够在后面执行自定义查询然后映射回来,即在该方面具有更大的灵活性)。如果它来了,这是一个很有前景的事情(尽管我预计不会很完美)。 (从好的方面来说,你实际上可以运行自定义查询,然后映射到你的对象 - 但是那种工作,你不能做所有事情,所以它在某种程度上是有限的)

Performance with queries and again for more demanding heavy duty scenarios - that was my main problem with it. That's also promised to come up better in EF 5.0 - so to wait and see.

查询性能以及更高要求的重型场景 - 这是我的主要问题。这也承诺在EF 5.0中更好 - 所以等等看。

Having said that -
my favorite is a custom or open source code first like solution, ORM - where you can have more things under control. Still having many providers support etc. is what makes 'official' or MS implementations more viable on a long run.

话虽如此 - 我最喜欢的是自定义或开源代码,首先就像解决方案,ORM - 你可以控制更多东西。仍有许多提供商支持等,这使得“官方”或MS实施从长远来看更加可行。

hope this helps any

希望这有助于任何

#1


7  

The upgrade scenario's you're describing are being added in EF-Migrations. The go-live release of this is already available and it should become available as a officially supported release version soon.

您正在描述的升级方案正在EF-Migrations中添加。该产品的上线版本已经发布,它很快就会作为官方支持的版本提供。

Check out: https://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx?Redirected=true

退房:https://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx?Redirected = true

Check out: http://coding.abel.nu/tag/ef-migrations/

查看:http://coding.abel.nu/tag/ef-migrations/

#2


3  

Just my take on this...

只是我对此的看法......

You don't need to make a choice for good -

你不需要做出好的选择 -

you can use Seed, custom initializer (and migrations hand in hand - with migrations you can actually manually change them, e.g. add indexes there etc. - though carefully), to 'inject' the raw SQL (and most of the needs could be covered by that). As far as I know you could run a custom batch file form initializer (but haven't tried, though I don't see why not). Migrations are done through PS so I'm guessing there is space to integrate on that side too.

您可以使用种子,自定义初始化程序(和迁移一起进行迁移 - 您可以实际手动更改它们,例如在那里添加索引等 - 尽管小心),“注入”原始SQL(并且可以涵盖大部分需求)那个)。据我所知,你可以运行自定义批处理文件表单初始化程序(但没有尝试,但我不明白为什么不)。迁移是通过PS完成的,所以我猜这个方面也有空间集成。

You can use it to prototype things and startup - get your C# structure in place and in sync fast - then shape it up later - or once fixed use some 'use existing initializer' which does nothing from the code and move everything to Db side and your DBA.

您可以使用它来原型化和启动 - 让您的C#结构就位并快速同步 - 然后再将其整形 - 或者一旦修复使用一些'使用现有的初始化程序',它不会对代码执行任何操作并将所有内容移动到Db端并且你的DBA。

IMO, you can go 'very far' in this sense, before actually needing to turn CF off and just work from Db.

IMO,你可以在这个意义上“走得很远”,然后才真正需要关闭CF并从Db开始工作。

For larger databases, or corporate environments, it's definitely not the right tool for the job.

对于较大的数据库或企业环境,它绝对不是适合这项工作的工具。

I think it's now safe for production - but depends on what you consider safe, few things...

我认为它现在可以安全生产 - 但取决于你认为安全的东西,很少的东西......

Also, EF/CF has gone a long way since the beginnings really - I used it since the start - and it had big problems initially. The latest versions are now pretty solid on all sides, so it's getting there I think.

此外,EF / CF从一开始就走了很长的路 - 我从一开始就使用它 - 而且它最初有很大的问题。最新版本现在各方面都很稳固,所以我认为它已经到了那里。

...on the downside - I had worked out some pretty complex scenarios with code first approach (EF and otherwise). However, few things held me back with EF (on top of what you mentioned)...

......在不利方面 - 我用代码优先方法(EF和其他方法)制定了一些相当复杂的场景。然而,很少有东西让我回到EF(在你提到的之上)......

UDF support, views (with linq - as if you're not to use LINQ one of the big 'pros' is gone) - which should come up in EF 5.0 (I did not check but it's what they're promissing) - as for more complex scenarios you need to optimize on the SQL side (or to be able to execute custom queries on the back and then map back, i.e. more flexibility on that side). So that's a promising thing if it comes (though won't be perfect I expect). (on the plus side, you can actually run custom queries and then map to your objects - but that sort of works, and you cannot do everything so it's limited in a way)

UDF支持,观点(使用linq - 就好像你不使用LINQ的一个大'专业'已经不见了 - 这应该出现在EF 5.0中(我没有检查,但这是他们的承诺) - 如对于更复杂的场景,您需要在SQL端进行优化(或者能够在后面执行自定义查询然后映射回来,即在该方面具有更大的灵活性)。如果它来了,这是一个很有前景的事情(尽管我预计不会很完美)。 (从好的方面来说,你实际上可以运行自定义查询,然后映射到你的对象 - 但是那种工作,你不能做所有事情,所以它在某种程度上是有限的)

Performance with queries and again for more demanding heavy duty scenarios - that was my main problem with it. That's also promised to come up better in EF 5.0 - so to wait and see.

查询性能以及更高要求的重型场景 - 这是我的主要问题。这也承诺在EF 5.0中更好 - 所以等等看。

Having said that -
my favorite is a custom or open source code first like solution, ORM - where you can have more things under control. Still having many providers support etc. is what makes 'official' or MS implementations more viable on a long run.

话虽如此 - 我最喜欢的是自定义或开源代码,首先就像解决方案,ORM - 你可以控制更多东西。仍有许多提供商支持等,这使得“官方”或MS实施从长远来看更加可行。

hope this helps any

希望这有助于任何