什么是开发中经常说的POCO

    在看一些EF的文章,经常提到POCO这个词,但是,有没有比较详细的说这个POCO是什么意思呢?

    POCO是指Plain Old Class Object,也就是最基本的CLRClass,在原先的EF中,实体类通常是从一个基类继承下来的,而且带有大量的属性描述。而POCO则是指最原始的Class,换句话说这个实体的 Class仅仅需要从Object继承即可,不需要从某一个特定的基类继承。主要是配合Code First使用。Cost Frist则是指我们先定义POCO这样的实体class,然后生成数据库。实际上现在也可以使用Entity Framework Power tools将已经存在的数据库反向生成POCOclass(不通过edmx文件)

    以下是stackoverflow中的回答:

    Cansomeone define what exactly 'POCO' means? I am encountering the term more andmore often, and I'm wondering if it is only about plain classes or it meanssomething more?

Answer:

    "PlainOld C# Object"

    Justa normal class, no attributes describing infrastructure concerns or otherresponsibilities that your domain objects shouldn't have.

    EDIT - as other answers havestated, it is technically "Plain Old CLR Object" but I, like DavidArno comments, prefer "Plain Old Class Object" to avoid ties tospecific languages or technologies.

    TO CLARIFY: In other words, theydon’t derive from some special base class, nor do they return any special typesfor their properties.

    Mostpeople have said it - Plain Old CLR Object (as opposed to the earlier POJO -Plain Old Java Object)

    The POJO one came out of EJB,which required you to inherit from a specific parent class for things likevalue objects (what you get back from a query in an ORM or similar), so if youever wanted to move from EJB (eg to Spring), you were stuffed.

    POJO'sare just classes which dont force inheritance or any attribute markup to makethem "work" in whatever framework you are using.

    POCO's are the same, except in.NET.

    Generallyit'll be used around ORM's - older (and some current ones) require you toinherit from a specific base class, which ties you to that product. Newer onesdont (nhibernate being the variant I know) - you just make a class, register itwith the ORM, and you are off. Much easier. 


本站文章除注明转载外,均为本站原创或翻译,欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,共创和谐网络环境。
转载请注明:文章转载自:
蓝狐软件工作室 » 什么是开发中经常说的'POCO'
本文标题:什么是开发中经常说的'POCO'
本文地址:http://www.lanhusoft.com/Article/309.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值