gpt4 book ai didi

entity-framework - 带有 Entity Framework 的参数化 POCO 构造函数

转载 作者:行者123 更新时间:2023-12-04 14:34:55 24 4
gpt4 key购买 nike

根据 Initial POCO Design 1-Pager

Persistence Ignorance refers to being able to allow the developer to write and test domain objects in a way that is entirely independent of fundamental requirements and assumptions that may be made by the infrastructure service (in this case, the Entity Framework). Such requirements / assumptions may often include:

  • The need to implement a specific interface (for e.g., IPOCO)
  • Inheritance from a base class
  • Providing specific constructors
  • Object Instantiation/Construction requirements – use a specific factory for instance**
  • The need for metadata or mapping class or property Attributes
  • The need to use specific relationship mechanisms

This amounts to being able to use Plain Old CLR Objects (POCO) so that a developer can author their domain objects free of all assumptions and requirements imposed by the framework. Using this approach, once the domain objects are ready to their satisfaction, the developer can use these classes with the Entity Framework in order for relational database access and persistence.



截至目前(CTP5),有什么办法可以使用参数化构造函数重构 poco 吗?如果不是,则很难看出 Entity Framework 如何提供持久性无知。

最佳答案

您可以拥有任意数量的参数化构造函数,只要框架可以访问一个无参数的构造函数,如果您没有构造函数,则默认情况下可用,或者如果您在创建的参数化构造函数之外提供一个构造函数.

关于entity-framework - 带有 Entity Framework 的参数化 POCO 构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4718978/

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