English 中文(简体)
统计? Repositories MVC3, EF4.2 (Code First)
原标题:Static? Repositories MVC3, EF4.2 (Code First)

I m new to MVC, EF and the so, I follow the MVC3 tutorial at http://www.asp.net/mvc 并提出了申请(尚未完成所有工作)。

这里指我迄今为止申请的“顺序”。

  • GenericRepository
  • PropertyRepository inherits GenericRepository for "Property" Entity
  • HomeController which has the PropertyRepository as Member.

例:

public class HomeController
{
    private readonly PropertyRepository _propertyRepository 
          = new PropertyRepository(new ConfigurationDbContext());
}

现在请考虑如下:

我在<密码>上有一套方法,需要相当一段时间,其中援引6个问题,需要在一个交易中处理,以便保持完整性。 我的洞察结果是,<代码>SaveChanges(......)被视为一种交易——因此,如果我对我的背景情况作多种改动,然后打电话<代码>SaveChanges(......)。 我可以“确保”这些改动是服务器上的“atomic”。 权利? 错误?

Furthermore, there s is an action method that calls _propertyRepository.InvokeLongAndComplex() Method. I just found out: MVC creates a new controller for each request. So I end up with multiple PropertyRepositories which mess up my Database Integrity. (I have to maintain a linked list of my properties in the database, and if a user moves a property it needs 6 steps to change the list accordingly but that way I avoid looping through all entities when having thousands...)

关于制作我的<代码>Generic Repository和我的PropertyRepository的静态,每一条<代码>HomeController都在使用相同的交存和同步。 InvokeLongAndComplex 有时只有一种途径对非行作出改变。

我怀疑这一想法不是一个好的解决办法,但我未能找到解决这一问题的适当办法,有些谎言说,有静态存放装置的征兆(情况如何)。 另一些论者则使用IOC/DI(?) ,它像许多工作一样完善(即使这解决了我的问题......),但似乎我“可以”集装箱总是“在同一个情况下”同一物体,即同一个存放地,这样就足以使<代码>InvokeLongAndComplex()>方法同步,不要让多个座右铭显示完整性。

Why aren t data repositories static? Answer 2:

2) 您往往希望每询问有1个存放处,以便更容易确保一个用户的不寻常变化不会给另一个用户带来麻烦。

为什么每询问有一个存放处,这又一次把我的联系名单提一下?

任何人能否向我提供咨询意见或交流我可以遵循的最佳做法?

问题回答




相关问题
SQL Server - How many users do I *really* need?

I m setting up an application, and I m looking into purchasing a license for SQL Server. My question is pretty simple (though may have a complicated answer...) How many users accounts do I really ...

Object Graph / Persistence Question

I m currently working with an online application that requires multiple screens/steps in order to complete. The application domain is modeled using an object graph. Persistence to and from a database ...

Why does stack get truncated in Exception.StackTrace?

Why does the high part of the stack (in Exception.StackTrace) gets truncated? Let s see a simple example: public void ExternalMethod() { InternalMethod(); } public void InternalMethod() { try ...

ASP.NET MVC and Service Oriented Architecture

I would like to know how do i incorporate a feature like wcf within and MVC application. My current idea of the architecture is as follows: EntityFramework -> ASP.NET MVC (Views) ...

热门标签