[英]Simple data manipulation: in Entity Model or Business layer?
I'm working on an asp.net MVC application that implements the traditional Data/ Business/Presentation layered approach. 我正在开发一个实现传统的数据/业务/演示分层方法的asp.net MVC应用程序。
One of my entity models (representing a person) contains address/contact information including a field for "State". 我的一个实体模型(代表一个人)包含地址/联系信息,其中包括“州”的字段。 My data source (which I have little control over) provides state values in full-text (Ex: "California" vs "CA", "Florida" vs "FL", etc). 我的数据源(我几乎无法控制)以全文本提供状态值(例如:“加利福尼亚”与“ CA”,“佛罗里达”与“ FL”等)。
I created a static helper class that we intend to use to transform the full-text values to their abbreviations. 我创建了一个静态帮助器类,打算将其用于将全文值转换为它们的缩写。
My question is, where should this helper class be referenced and where should the transformation take place? 我的问题是,应该在哪里引用该帮助器类,以及在哪里进行转换?
I see the following options: 我看到以下选项:
public string State { get { return StateConverter.Abbreviate(_state); } }
perform the conversion in the business layer whenever this entity model used 每当使用此实体模型时,在业务层中执行转换
Perform the conversion in the presentation layer whenever this value is displayed 每当显示此值时,在表示层中执行转换
I like the simplicity of having this take place in the actual model (via get accessor), but this smells a tiny bit like business logic. 我喜欢在实际模型中(通过get访问器)进行操作的简单性,但这有点像业务逻辑。 The other options mean that I will have to convert this in many places (duplicating logic, traversing through people lists, etc). 其他选项意味着我将不得不在许多地方进行转换(复制逻辑,遍历人员列表等)。
Thanks. 谢谢。
It is okay to put it inside your model since it is just a computed field. 可以将其放入模型中,因为它只是一个计算字段。 Moreover your Abbreviate(...) method doesn't even depend on any data outside your model. 而且,您的Abbreviate(...)方法甚至不依赖于模型之外的任何数据。 Your right to put it there. 您有权将其放在那里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.