首页 \ 问答 \ MVC +存储库模式 - 仍取决于数据模型?(MVC + Repository Pattern - Still depends on Data Model?)

MVC +存储库模式 - 仍取决于数据模型?(MVC + Repository Pattern - Still depends on Data Model?)

我已经开始了一个学校项目,我正在使用ASP.NET MVC 2 + LINQ2SQL和业务层,所以我的UI不直接与DB交互。 我的问题是:

在我的MVC项目中,当提出视图和传递数据时,我仍然必须包含我的Data项目以访问我的Linq2Sql项目中的类。 它是否正确?

例:

控制器:

ClassesRepository cr = new ClassesRepository(); // this is from my Business project
Class classToEdit = cr.GetByClassId(id); // "Class" is from my data project

我仍然需要在我的linq2sql数据项目中引用Class类 - 我的UI不应该完全独立于我的数据层吗? 或者也许我说这一切都错了。


I've started a project for school in which I am using ASP.NET MVC 2 + LINQ2SQL, and a business layer so my UI doesnt interact with the DB directly. My question is this:

In my MVC project, when bringing up views and passing around data, I still have to include my Data project for access to the classes in my Linq2Sql project. Is this correct?

Example:

Controller:

ClassesRepository cr = new ClassesRepository(); // this is from my Business project
Class classToEdit = cr.GetByClassId(id); // "Class" is from my data project

I still have to reference the Class class in my linq2sql data project - shouldn't my UI be completely independent of my data layer? Or maybe I'm going about this all wrong.


原文:https://stackoverflow.com/questions/2717247
更新时间:2022-05-29 10:05

最满意答案

在不更改属性名称的情况下,可以将对象映射到相关对象

  .map((response: Response) =>  
     <processGroup[]>response.json()
     .map(function(elem){ return { processGroupName: elem["groupName"]} });

Without changing property name you can map your object to relevant object

  .map((response: Response) =>  
     <processGroup[]>response.json()
     .map(function(elem){ return { processGroupName: elem["groupName"]} });

相关问答

更多
  • 这是因为jquery.d.ts将parseJSON定义为: parseJSON(json: string): Object; 它应该是任何。 您可以自己转换结果以避免创建接口 var parsedJSON = $.parseJSON(jqXHR.responseText); var r = parsedJSON.ResponseStatus; 要么: var parsedJSON:any = $.parseJSON(jqXHR.responseText); var r = parsedJSO ...
  • 这些是一些快速的镜头,以显示几种不同的方式。 他们绝对不是“完整”,作为免责声明,我不认为这样做是个好主意。 此外,代码不是太干净,因为我只是快速地键入它。 另外作为一个注释:当然,可反序列化的类需要具有默认的构造函数,就像我知道任何类型的反序列化的所有其他语言一样。 当然,如果你调用一个没有参数的非默认构造函数,Javascript不会抱怨,但是这个类更好地为它准备好了(加上它不会是“typescripty方式”)。 选项#1:根本没有运行时信息 这种方法的问题主要是任何成员的名称必须与其类匹配。 它会自 ...
  • 您不能简单地将Ajax请求中的简单JavaScript结果转换为原型JavaScript / TypeScript类实例。 有很多技巧来做,通常涉及复制数据。 除非你创建一个类的实例,否则它不会有任何方法或属性。 它将仍然是一个简单的JavaScript对象。 虽然如果你只是处理数据,你可以做一个转换到一个接口(因为它纯粹是一个编译时结构),这将要求你使用一个TypeScript类,它使用数据实例并且执行与该数据的操作。 复制数据的一些示例: 将AJAX JSON对象复制到现有对象中 将JSON字符串解析为 ...
  • 你在找这样的东西吗? 首先获取对象键,然后遍历这些键,然后循环遍历嵌套的对象键 var jso = { "-KtDGS8GdOcJ33Lcqjok": { "2017": { "address": "test address 1", "area2": "3212", "author": "STOkzlbT4OeOcbO2ed9Z7dvxZk92", "category": "Solar", "client" ...
  • 您可以像这样输入: (response.query as Query).startDate = (new Date()).toUTCString(); 或者你可以有另一个变量: let response2 = response as AwesomeLibrary & { query: Query }; response2.query.startDate = (new Date()).toUTCString(); 您还可以接收此类型的参数: function functionCb(response: Aw ...
  • 您确实可以指定返回object ( 对typescript 2.2新增 ),但您可以为返回值创建一个类型: type MyReturnTypeItem = { vars: string[]; smps: string[]; data: string[]; } type MyReturnType = { [name: string]: MyReturnTypeItem; } function formaterDonnees(data: string): MyReturnTy ...
  • 那是因为您的类别Category没有任何属性。 您可以定义参数属性以直接从构造函数参数创建属性: export class Category{ constructor( public id: string, public name: string, public category_types: Object[] ) {} } 现在, Category所有参数也是它的公共属性。 That is because your class Category does not have ...
  • 在不更改属性名称的情况下,可以将对象映射到相关对象 .map((response: Response) => response.json() .map(function(elem){ return { processGroupName: elem["groupName"]} }); Without changing property name you can map your object to relevant object .map((r ...
  • 您正在做什么将类视为接口,因为这将完全相同: export interface User { id : number; name : string; email : string; } 编译器没有抱怨你这样使用类的原因是因为 : TypeScript的核心原则之一是类型检查关注于值所具有的形状。 这有时被称为“鸭子打字”或“结构子类型” ( 阅读更多关于鸭子打字的信息 或者举个例子: class User { id: number; name: string; ...
  • 不,PHP不允许你这样做。 将对象分配给类属性的唯一方法是通过类方法。 如果您希望在对象初始化时将空类分配给类属性,则可以通过构造函数方法执行此操作。 class xxx { public $array = array(); public $object1; public function __construct() { $this->object1 = new stdClass(); } } No, PHP does not allow you to d ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)