gpt4 book ai didi

asp.net-mvc-4 - 使用 MVC 4 和 EF 5 创建 n 层

转载 作者:行者123 更新时间:2023-12-01 03:54:31 25 4
gpt4 key购买 nike

我正在创建 n 层应用程序,我将有两个单独的项目

1) project EF (where it will have all my edmx...)
2) project MVC 4 (internet application.)

在我的 EF 中,我有我的 .edmx文件并生成几个具有所有 Prop 的类,如下所示(作为示例)...
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
public partial class Requester
{
public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
<//more...........>
}

到目前为止一切都很好!
Back to MVC project
现在我将在我的 MVC 项目中创建一个新的 Controller ,当我尝试创建 Scaffolding 时并提供 Controller姓名和 Controller预计 Model所以真正的问题是:

什么 Model我应该经过这里吗?
我应该拥有与 EF 创建相同的类(class)吗?或者我应该创建另一个 Model在我的“模型文件夹”(MVC)中并绑定(bind)它?如果是,那么如果我继续在 MVC 模型文件夹项目中创建相同的模型,我是否不会创建重复的属性?

我想做什么? :嗯,我这个练习的目的是让我的数据访问层(DAL)与 MVC 项目完全分离。

有什么想法吗?

最佳答案

我建议创建一个 View 模型,以便您可以使用与 View 相关的东西(即 UIHint)来装饰属性。此外,此 View 模型将是该类的简化版本(例如,它可以仅包含相关对象的 id 而不是整个对象),使其更易于用作操作参数。

另外,您在这里谈论对象,尽量不要考虑“数据”。

关于asp.net-mvc-4 - 使用 MVC 4 和 EF 5 创建 n 层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18500543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com