ASP.NET MVC 应用程序的数据库和逻辑层

发布于 2024-09-03 18:15:39 字数 839 浏览 2 评论 0原文

我将开始一个新项目,最初规模很小,但随着时间的推移可能会变得很大。我坚信我将使用 ASP.NET MVC 和 jQuery 作为 UI。由于某些原因,我想使用 MySQL 作为数据库,但担心一些事情。

我对 Linq 完全陌生,但一旦熟悉它似乎就更容易使用。

首先,访问数据应该很容易。所以我想我应该使用 MySQL to Linq,但我在某处读到它不直接支持,但 MySQL .NET 连接器添加了对 EntityFramework 的支持。我不知道它的优点和缺点是什么。我也听说过DbLinq。如果我可以实现存储库模式,我会很高兴,因为它允许在逻辑层而不是数据访问层应用过滤器。如果我使用实体框架可以吗?

我也关心表演。有人告诉我,如果我们使用实体框架,它会获取大量数据,然后对其进行过滤。是这样吗?

所以问题基本上是 -

  1. MySQL 到 Linq 可能吗?如果是,我可以在哪里获得更多详细信息?
  2. 在 MySQL 中使用 EntityFramework 或 DbLinq 的优点和缺点?
  3. 使用 EntityFramework 或 DbLinq 与 MySQL 访问数据是否容易?
  4. 我是否能够实现存储库模式,该模式允许在逻辑层而不是数据访问层应用过滤器(当我将 EntityFramework 与 MySQL 一起使用时)
  5. 它是否从数据库中获取大量数据,然后对其应用过滤器?

如果在这种情况下,我这边的问题听起来太多了,如果您能让我知道您作为该领域的经验丰富的人在这种情况下会做什么(有相当大的理由),那就应该回答我的问题。

I'm going to start a new project which is going to be small initially but may grow to big over the years. I'm strongly convinced that I'm going to use ASP.NET MVC with jQuery for UI. I want to go for MySQL as database for some reasons but worried on few things.

I'm totally new to Linq but it seems that it is easier to use once you are familiar with it.

First thing is that accessing data should be easy. So I thought I should use MySQL to Linq but somewhere I read that it is not directly supported but MySQL .NET connector adds support for EntityFramework. I don't know what are the pros and cons of it. DbLinq is what I also heard. I would love if I can implement repository pattern as it allows to apply filter in logic layer rather than in data access layer. Will it be possible if I use Entity Framework?

I'm also concerned about the performance. Someone told me that if we use Entity framework it fetches lot of data and then filter it. Is that right?

So questions basically are -

  1. Is MySQL to Linq possible? If yes where can I get more details on it?
  2. Pros and cons of using EntityFramework or DbLinq with MySQL?
  3. Will it be easy to access data using EntityFramework or DbLinq with MySQL?
  4. Will I be able to implement repository pattern which allows applying filter in logic layer rather than data access layer (when I use EntityFramework with MySQL)
  5. Does it fetches hell lot of data from database and then apply filter on it?

If it sounds too many questions from my side in that case, if you can just let me know what you will do (with a considerable reason) in this situation as an experienced person in this area, that should answer my question.

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

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

发布评论

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

评论(2

忘羡 2024-09-10 18:15:39

由于我是 ALT.NET 的粉丝,我建议您在项目中使用 NHibernate 而不是 EntityFramework,您可以通过 google 搜索它的优势,我相信您会选择它。

As I am fan of ALT.NET I would recomend you to use NHibernate for your project instead of EntityFramework, you may google for the advantages over it, I am convinced you'll choose it.

掌心的温暖 2024-09-10 18:15:39

基于您提到的几点,那么我会认真考虑最初使用 MS SQL 而不是 MySQL,并实现 LINQ-to-SQL 而不是实体框架,原因如下:

  1. 您最初预计会有大量流量这一事实表明我认为你需要考虑你打算在哪里结束,而不是从哪里开始。我在 MS SQL 方面的经验比在 MySQL 方面的经验要多得多,但是如果您正在谈论从 MySQL 的社区版本开始并稍后升级,那么您无论如何都会在企业版本中产生大量费用。
  2. 我听说有一个支持 MySQL 的 LINQ 版本,但是,除非最近发生了变化,否则它仍处于测试阶段。我正在完成一个为期 18 个月的基于 Web 的项目,该项目使用 ASP.NET MVC 1.0、LINQ-to-SQL、JavaScript、jQuery、AJAX 和 MS SQL。我使用 WatiN 实现了存储库模式、视图模型、接口、单元测试和集成测试。这些技术的组合对我来说非常有效,我计划在我正在开发的个人项目中采用相同的组合。
  3. 当您通过托管计划获得 MS SQL 时,您通常能够从该单个实例创建多个数据库。看起来它们为您提供了更多存储空间,因为它们为您提供了多个 MySQL 数据库,但这只是因为该架构仅支持每个实例创建一个数据库。
  4. 我不会在 ASP.NET MVC 项目中使用实体框架,因为我一开始并不热衷于 ADO.NET。我不想打开连接、创建命令对象、填充参数集合、发出执行方法,然后迭代单向读取器对象来获取数据。一旦您了解 LINQ-to-SQL 如何简化该过程,您就不会想再回头了。在我前面提到的项目中,我的数据库中有 60 多个表,大约有 200 个外键关系。因为我在数据层中使用了 LINQ-to-SQL 和存储库模式,所以我能够使用而不是单个存储过程来构建应用程序。 LINQ-to-SQL 自动防御 SQL 注入攻击,并支持乐观和悲观并发检查。

我不知道您的项目是什么,但您不想陷入稍后扩展应用程序时遇到麻烦的情况。为最终结果而不是起点编写代码,这样您以后就会避免很多麻烦。

Based on the points you've mentioned, then I would seriously consider going with MS SQL instead of MySQL initially and implementing LINQ-to-SQL instead of Entity Framework, and here's why:

  1. The fact that you are anticipating a lot of traffic initially tells me that you need to think about where you plan to end up, rather than where to start. I have considerably more experience with MS SQL than I do with MySQL, but if you're talking about starting with the community version of MySQL and upgrading later, you're going to be incurring a significant expense anyway with the Enterprise version.
  2. I have heard there is a version of LINQ that supports MySQL, but, unless things have changed recently, it is still in beta. I am completing an 18-month web-based project that used ASP.NET MVC 1.0, LINQ-to-SQL, JavaScript, jQuery, AJAX, and MS SQL. I implemented the repository pattern, view models, interfaces, unit tests and integration tests using WatiN. The combination of technologies worked very well for me, and I plan to go with the same combination for a personal project I'm developing.
  3. When you get MS SQL with a hosting plan, you typically have the ability to create multiple databases from that single instance. It looks like they give you more storage because they give you multiple MySQL databases, but that's only because the architecture only supports the creation of one database per instance.
  4. I won't use the Entity Framework for my ASP.NET MVC projects, because I wasn't crazy about ADO.NET in the first place. I don't want to have to open a connection, create a command object, populate a parameter collection, issue the execute method, and then iterate through a one-way reader object to get my data. Once you see how LINQ-to-SQL simplifies the process, you won't want to go back either. In the project I mentioned earlier, I have over 60 tables in the database with about 200 foreign key relationships. Because I used LINQ-to-SQL with the repository pattern in my data layer, I was able to build the application using not a single stored procedure. LINQ-to-SQL automatically protects against SQL injection attacks and support optimistic and pessimistic concurrency checking.

I don't know what your project is, but you don't want to get into a situation where you're going to have trouble scaling the application later. Code for the end result, not for the starting point, and you'll save yourself a lot of headaches later.

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