dto

为什么我们要使用DTO

╄→尐↘猪︶ㄣ 提交于 2019-11-28 08:03:55
基础结构解释 UI-表现层-与控制器打交道(UI向Controller 传递数据时使用DTO(数据传输对象)) Service-应用服务层 Domain 领域对象 DTO 数据传输对象,一般只包含基础的Get,Set功能,也会包含一些数据验证,如必填项,大小,自定义规则等。 一个完整的业务是通过领域实体(对象)domain建立的,而DTO是根据UI的需求来设计的。 比如:Customer领域对象可能会包含一些诸如FirstName, LastName, Email, Address等信息。但如果UI上不打算显示Address的信息,那么CustomerDTO中也无需包含这个 Address的数据。 比如:User表设计字段如下:Id,UserName,Password,RegisterTime。注册时,那这个接口的参数应该只有UserName,Password,因为RegisterTime是后台赋值的,Id是数据库自动生成的。即设计一个RegisterDto,只包含UserName,Password二个字段,作为注册接口的参数。不然,那二个参数对于开发前端的人来说是无意义的,因为传递也没有效果。所以不应该暴露给前端使用。 以上即领域对象来实现业务,DTO只注重数据。 UI->Controller(通过 DTO完成数据传输,表单验证)->Service(操作Domain,完成业务服务

LINQ to map a datatable into a list<MyObject>

家住魔仙堡 提交于 2019-11-28 06:37:21
I just discover LINQ so be comprehensive with me please! :-) So! I have a Data-tier who provide me datatables and i want to convert them into lists of objects. These objects are defined in a spécific layer DTO (Data transfer Objects). How can I map every rows of my datatable into objects and put the all objects into a list? (today i make it "manually" field after field) Is it possible with LINQ? I've heard about LINQ2Entities? am i right? Thanks to help a beginner to understand... Tomas Jansson If the objects is not too complex you can use this: public static class DataTableExtensions { public

What is the difference between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?

孤者浪人 提交于 2019-11-28 05:55:35
I cannot find difference between them. Does anyone know how to differentiate them? POJO or "Plain Old Java Object" is a name used to describe "ordinary" Java objects, as opposed to EJBs (originally) or anything considered "heavy" with dependencies on other technologies. DTO or "Data Transfer Object" is an object for... well... transferring data, usually between your "business" classes and persistence layer. It typically is a behavior-less class much like a C-style struct. They are an outdated concept. Jon A POJO is just a simple Java object, the acronym is used to emphasize that it really is

How to use DTO in JSF + Spring + Hibernate

老子叫甜甜 提交于 2019-11-27 22:33:16
Assuming that i'm new about the topic DTO. I can't understand if it is correct to use the DTO in tandem with JSF, Spring and Hibernate. Let me explain, so far I have used the entity bean, created directly from the database, both in business layer and in the presentation layer. Now I decided to try using the DTO approach, but I can not understand how they can help. For example if I have two classes User and Message, and a user has more messages associated; how can I populate the DTO from the database? Or do I manually populate the DTO at the business layer? can someone post an example on how to

Data transfer object pattern

允我心安 提交于 2019-11-27 20:45:24
问题 i'm sorry i'm newbie to enterprise application as well as the design pattern. might be this question occcur lack of knowledge about design pattern. i found that its better to use DTO to transfer data. my business entity class as below: public class Patient { public string ID { get; set; } public string FullName { get; set; } public string FirstName { get; set; } public string Surname { get; set; } } so in my application user only give ID and HospitalID. so it calls for another web service and

An ASP.NET MVC validator to make sure at least one checkbox is checked

爷,独闯天下 提交于 2019-11-27 18:22:48
问题 I have an ASP.NET MVC 2 project in which I've created a data transfer object to receive data from a web page form. The form has two groups of checkboxes on it. I want to validate the object to make sure that at least one of the checkboxes in each group is checked. I'm doing the validation on the server side so that a user won't be able to hack around any client-side validation. (I will add client-side validation with jQuery later; that's easy.) My understanding is that I have to create my own

DTO = ViewModel?

非 Y 不嫁゛ 提交于 2019-11-27 17:04:23
I'm using NHibernate to persist my domain objects. To keep things simple I'm using an ASP.NET MVC project as both my presentation layer, and my service layer. I want to return my domain objects in XML from my controller classes. After reading some posts here on Stack Overflow I gather DTOs are the way to go. However, I've also come across posts talking about the ViewModel. My question: Are Data Transfer Objects and ViewModels the same thing? Or is a ViewModel a kind of sub pattern of a DTO? The canonical definition of a DTO is the data shape of an object without any behavior. ViewModels are

WCF Message & Data Contract, DTO, domain model, and shared assemblies

情到浓时终转凉″ 提交于 2019-11-27 17:03:50
问题 I have a web client that calls my WCF business service layer, which in turn, calls external WCF services to get the actual data. Initially, I thought I would use DTOs and have separate business entities in the different layers... but I'm finding that the trivial examples advocating for DTOs, to be, well, trivial. I see too much duplicate code and not much benefit. Consider my Domain: Example Domain I have a single UI screen (Asp.net MVC View) that shows a patient's list of medications, the

Nullable object must have a value

半城伤御伤魂 提交于 2019-11-27 15:59:34
报错信息: Nullable object must have a value 翻译过来就是:可为空的对象必须具有一个值。 看起来有点怪怪的,既然是可空对象为什么必须要有值吗?下面我们就探讨一下吧.... 举个列子,开发过程中可能碰到的一个场景: 有一个类Goods,这个类有很多的属性,其中有一个Price属性为可空double类型, 我们需要另外一个类GoodsDto 来接收Goods对象并输出,其中也有一个Price属性 为double类型。我们可以看到报错了 double?转double,因为double?可能是空的,但是double转double?不会报错,因为double永远都有值,而且double?可接受空值 那么怎么处理呢? GoodsDto dto = new GoodsDto() { GoodsName = goods.GoodsName, GoodsNo = goods.GoodsNo, Price = goods.Price.Value };  再次运行下,发现报错Nullable object must have a value,什么情况呢? 其实稍微分析一下就不难理解了,回到根源还是double?转double的问题 goods.Price没值的话,goods.Price.Value就是空值, dto.Price是不可能接受的。 虽然你是可空的

How do you map a Dto to an existing object instance with nested objects using AutoMapper?

让人想犯罪 __ 提交于 2019-11-27 13:18:46
I have the following Dto and entity with a nested sub entity. public class Dto { public string Property { get; set; } public string SubProperty { get; set; } } public class Entity { public string Property { get; set; } public SubEntity Sub { get; set; } } public class SubEntity { public string SubProperty { get; set; } } How can I set up a mapping with AutoMapper that will allow me to update an existing instance of Entity with the values from a Dto . I'm using Mapper.Map(dto, entity) to update an existing entity but when I try to map Dto.SubProperty to Entity.Sub.SubProperty I get an exception