EF4、MVC 3、Azure 和 Code First 或传统

发布于 2024-10-11 06:18:30 字数 293 浏览 8 评论 0原文

我计划使用 ASP MVC3 构建一个 Web 应用程序,该应用程序在带有 SQL Azure 后端的 Azure 上运行。我想使用 Microsoft 堆栈,并且不打算更改为其他堆栈。我正在研究 WCF 和 WF 的使用,但这将是将来的事。

我研究了使用实体框架的传统方法和代码优先方法,但我看不出使用其中一种方法是否有任何优势。当然,它们各有优点,但对我来说,我不在乎我的类是否继承自 EF 类。我想要的只是找到最有效的解决方案。

任何人都可以给我一些建议,告诉我哪种方法可能是最好的。

非常感谢

理查德

I am planning to build a web application using ASP MVC3 that runs on Azure with a SQL Azure back end. I would like to use the Microsoft stack and have no plans to ever change to another stack. I am looking into the use of WCF and WF but that would be in the future.

I looked at the traditional and Code First approach to using Entity Framework but I can't see if there is any advantage in using one or the other approach. Sure they each have advantages but for me I don't care if my classes do inherit from EF classes. All I want is to find the most efficient solution.

Can anyone out there give me some advice as to which approach might be the best.

thanks very much

Richard

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

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

发布评论

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

评论(4

青巷忧颜 2024-10-18 06:18:30

这实际上更多的是一个意见收集问题,可能更多地属于 StackExchange 的程序员网站,但我会尝试一下:

我绝对是一个传统方法的人。对我来说,数据是关键。这是最重要的。各种对象、层、应用程序、服务来来去去并不断发展。但数据依然存在。这就是我首先设计数据库的原因。根据我的经验,数据始终为王。

This is really more of an opinion gathering question and probably belongs more to the Programmers site of StackExchange, but I'll take a stab:

I am definitely a traditional approach kind-of-a-guy. To me, data is key. It is most important. Various objects, layers, applications, services come, go and evolve. But data lingers on. Which is why I design my databases first. In my experiences, data has always been king.

轻许诺言 2024-10-18 06:18:30

我会采用“代码优先”方法。

这个伟大的博客Scott Guthrie 的帖子解释了它的优点。

I'd go with Code First approach.

This great blog post by Scott Guthrie explains its advantages.

一曲琵琶半遮面シ 2024-10-18 06:18:30

我也先写代码。如果您突然开始讨厌实体框架并想切换到 NHibernate,那么您手上的工作就会少很多。

此外,通过将域层与数据访问层完全隔离,可以更清晰地分离关注点。

我不是100%确定它仍然适用,但我认为实体框架的代码生成、部分类虚言可能会在测试时引起问题。

我是否首先提到代码可以减少很多麻烦。

Code first for me also. If you suddenly started to hate Entity Framework and wanted to switch to NHibernate you will have a lot less work on your hands.

Also, there is a cleaner separation of concerns by totally isolating your domain layer from your data access layer.

I am not 100% sure it still applies, but I think the code generation, partial class malarky of entity framework can cause problems when testing.

Did I mention code first is a lot less hassle.

埖埖迣鎅 2024-10-18 06:18:30

Code First 是一种“架构上正确”的方法,但当您必须考虑工作量、价值和开发速度时,现实往往会有所不同。

使用“模型优先”方法会更快且更容易维护。只需右键单击“从数据库重新生成”即可传播数据库更改,当您忘记更改属性名称或类型时,您的代码中不会出现奇怪的错误。

话虽如此,您可以通过 EF4 中新的 POCO 支持两者兼得。您可以删除对基类的依赖关系,同时使用建模工具:

此线程中有很多很好的链接:

实体框架 4 / POCO - 从哪里开始?

Code First is an "Architecturally correct" approach, but reality tends to differ on these things when you have to consider effort, value, and speed of developement.

Using the "Model First" approach is much faster and easier to maintain. Database changes propagate with a simple right click "Regen from database", you don't get strange errors creeping into your code when you forget to change a property name or type.

Having said that you can have a bit of both with the the new POCO support in EF4. You can remove the dependencies on base classes while at the same time use the modelling tools:

A lot of good links in this thread:

Entity Framework 4 / POCO - Where to start?

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