简体   繁体   English

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

[英]Database and logic layer for ASP.NET MVC application

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. 我坚信我将使用ASP.NET MVC和jQuery for UI。 I want to go for MySQL as database for some reasons but worried on few things. 由于某些原因,我想将MySQL用作数据库,但担心的是几件事。

I'm totally new to Linq but it seems that it is easier to use once you are familiar with it. 我对Linq完全陌生,但是一旦您熟悉它,它似乎更易于使用。

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. 因此,我认为我应该在Linq上使用MySQL,但是我读到某个地方它没有直接支持,但MySQL .NET连接器增加了对EntityFramework的支持。 I don't know what are the pros and cons of it. 我不知道它的优点和缺点。 DbLinq is what I also heard. 我也听到了DbLinq。 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? MySQL可以用于Linq吗? If yes where can I get more details on it? 如果是,我在哪里可以获得更多详细信息?
  2. Pros and cons of using EntityFramework or DbLinq with MySQL? 在MySQL上使用EntityFramework或DbLinq的优缺点?
  3. Will it be easy to access data using EntityFramework or DbLinq with MySQL? 使用EntityFramework或DbLinq和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) 我将能够实现允许在逻辑层而不是数据访问层中应用过滤器的存储库模式(当我将EntityFramework与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. 如果在这种情况下在我这边听起来有太多问题,如果您可以让我知道在这种情况下作为该领域的有经验的人您将做的事情(有充分的理由),那应该回答我的问题。

因为我是ALT.NET的粉丝,所以我建议您将NHibernate用于您的项目而不是EntityFramework,您可以在Google上寻求它的优点,我相信您会选择它。

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: 基于您提到的观点,然后我将认真考虑最初使用MS SQL而不是MySQL并实现LINQ-to-SQL而不是Entity Framework,这是为什么:

  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. 与使用MySQL相比,我在MS SQL方面的经验要丰富得多,但是如果您要谈论的是从MySQL的社区版本开始并在以后进行升级,则无论如何,企业版本都将产生大量费用。
  2. I have heard there is a version of LINQ that supports MySQL, but, unless things have changed recently, it is still in beta. 我听说有一个支持MySQL的LINQ版本,但是,除非最近有所变化,否则它仍处于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. 我正在完成一个为期18个月的基于Web的项目,该项目使用了ASP.NET MVC 1.0,LINQ-to-SQL,JavaScript,jQuery,AJAX和MS SQL。 I implemented the repository pattern, view models, interfaces, unit tests and integration tests using WatiN. 我使用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. 使用托管计划获取MS SQL时,通常可以从该单个实例创建多个数据库。 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. 看起来它们为您提供了更多的存储空间,因为它们为您提供了多个MySQL数据库,但这仅仅是因为该体系结构仅支持为每个实例创建一个数据库。
  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. 我不会在ASP.NET MVC项目中使用实体框架,因为首先我并不对ADO.NET感到疯狂。 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. 我不需要打开连接,创建命令对象,填充参数集合,发出execute方法,然后遍历单向读取器对象来获取我的数据。 Once you see how LINQ-to-SQL simplifies the process, you won't want to go back either. 一旦您了解了LINQ-to-SQL如何简化了这一过程,就不会再回头了。 In the project I mentioned earlier, I have over 60 tables in the database with about 200 foreign key relationships. 在我前面提到的项目中,数据库中有60多个表,其中包含约200个外键关系。 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与存储库模式一起使用,所以我能够使用单个存储过程来构建应用程序。 LINQ-to-SQL automatically protects against SQL injection attacks and support optimistic and pessimistic concurrency checking. LINQ-to-SQL自动防御SQL注入攻击,并支持乐观和悲观的并发检查。

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. 为最终结果而不是起点编写代码,以后您将省去很多麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM