English 中文(简体)
如果我们把LLBL ORM实体作为参数纳入控制器行动方法,
原标题:Should we put LLBL ORM entity object into the controller action method as parameter

ASP NET solution we are working on consists of multiple layers, user interface is developed using asp net mvc 2 web form view engine with extensively use of template editors and data annotations (recently we upgraded it to asp net mvc 3). For instance, we have Create action in RegistrationController:

        [HttpPost]
        public ActionResult Create(PersonViewModel person)
        {

            try
            {
                if (!ModelState.IsValid)
                {
                    return View(person);
                }
                else
                {
             var personInterface = BusinessRegister.PersonHandler.Save(person);
                    return View("Edit", personInterface);
                }

            }
            catch {

            }
        }

因此,我们有个人意见书Model,其出席之处是把从浏览器传递的信息与控制器行动联系起来的简单数据传输标。 此外,它叫Handler。 Save (behind this callstay WCF Service responsible for seriesizing transmitted Object into PersonEntity (LLBL Object).

之所以出现这一问题,是因为世界钻石联合会需要合同,所以它不知道与HerViewModel(或如何将其序列化)有何关系,因此,首席建筑师建议直接在有ORM实体的所在地和变更控制人签名的集会上提及。 因此,现在我们的控制者会想像我们的控制者。

[HttpPost]       
 public ActionResult Create(PersonEntity person)
        {
….

I am asking you for help – is it correct doing it this way - putting ORM entity behind default model binder of mvc framework? I am not sure this is best modeling practice -shoudn’t it be viewModel instead so we can later use some kind of mapping to PersonEntity? Or, better, how to avoid tightly coupling here (which is obvious). Thank you in advance.

问题回答

利用OMA实体类别作为控制者行动的一个参数,从你向下层提出申请的顶层向下层扔下了一条难以依赖的右.。

我认为,这条路将严重影响到你改变申请的能力。

现在,你必须把贵实体的任何变动与制作《持久性有机污染物行动计划》的超文本格式调和。 这一点非常糟糕,面对我所看到的关于多国师协会的每一项最佳做法建议,情况就是如此。

3 一种价格的答案:

  1. Automapper (automapper.codeplex.com)
  2. Use it
  3. Love it <3

I think it is depend on your business logic and actual needs. For simple use why not directly use Domain Entity? I do not see any reason to use ViewModel or View Object,etc. Domain Entity normally do not need to be test if only work as data container. If you have rich domain entity, I think you should create a ViewModel to do this. If you need consider performance such as load a big list or need fetch some information cross different tables, I recommend you use View Object and manually create sql for ORM to use.





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签