简体   繁体   English

简单的数据操作:在实体模型还是业务层?

[英]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: 我看到以下选项:

  • Use an accessor in the model that references this static class and performs the transformation on get. 在引用此静态类并在get上执行转换的模型中使用访问器。 Something along the lines of: 类似于以下内容:
 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.

相关问题 如何在业务层和/或数据层中使用实体框架? - How to use entity framework in business layer and/or data layer? 将域模型业务实体传递给UI层问题 - Passing domain model business entity to UI layer question 我应该在业务层还是数据访问层新建数据库 model - Should i new database model in business layer or data access layer 在单独的数据访问和业务逻辑层中,我可以在业务层中使用Entity框架类吗? - In separate data access & business logic layer, can I use Entity framework classes in business layer? 使用实体框架时,业务逻辑层中的数据对象 - Data Objects in Business Logic Layer when using Entity Framework 是MVC模型Poco类,具有数据层或业务层的结构? - is MVC model Poco class, structure having data or business layer? 业务对象和数据层 - Business Objects and Data Layer 演示文稿,业务和数据层 - Presentation, Business and Data Layer 当使用实体框架作为数据访问层时,如何实现业务逻辑层? - How do you implement a business logic layer when using entity framework as data access layer? REST体系结构:数据访问层作为模型,REST的目的是调用调用DAL的业务逻辑层 - Rest Architecture: Data Access Layer as Model, REST purpose is to call Business Logic Layer that calls DAL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM