有的時候我們在建立完實體之後發現,由于自己的不小心,在建立實體關系選項中删除了注釋(包括附件)的功能,或者由于之前考慮的不周到,沒想到該實體将來會使用到附件的功能,這樣的話,如果實體簡單,可以通過删除建立然後完成,如果實體中字段過多,這個過程就相當的麻煩了。下面是我使用的一種方法,用來改變這個狀态。
首先請備份資料庫
- 建立兩個實體new_noattachment,new_attachment。new_noattachment建立的時候将關系中的附件勾去掉,new_attachment這個保留
- 導出這兩個實體的XML,使用XML對比工具(例如:ExamXML),對比一下這兩個實體有什麼地方是不一緻的
- 發現不一緻的地方主要有兩個:FormXml這個節點裡面的tabs裡面少一個tab(這個tab就是用來添加注釋或者附件的);在EntityRelationships節點裡面少了一個關系,關系是和實體Annotation對應起來的。上面兩個不一樣的地方比較容易對比出來,但是還有一個比較隐蔽的地方,因為實體的不一直,可能你會在意不到,但是如果這個地方不改動的話更改完成導入之後會有錯誤産生:The entity relationship role of the referencing entity is required when creating a new one-to-many entity relationship new_noattachment_Annotations。 這個需要注意的地方就是在EntityInfo節點裡面的HasRelatedNotes這個節點的值,如果是False請修改為True
- 修改HasRelatedNotes節點的值,将False修改為True
- 在FormXml的tabs裡面添加一個tab,tab如下:
<tab id="{4f91fc75-4667-4e75-a628-212b09a6257e}" IsUserDefined="0">
<labels>
<label description="注釋" languagecode="2052" />
</labels>
<sections>
<section showlabel="true" showbar="true" locklevel="1" id="{84de336e-7eaa-49a3-b119-d4190792e6d9}" IsUserDefined="0" height="auto">
<labels>
<label description="注釋" languagecode="2052" />
</labels>
<rows>
<row>
<cell colspan="2" showlabel="false" rowspan="5" auto="true" id="{46a7d824-10c2-4476-906a-d8efaea4f5df}">
<labels>
<label description="注釋文字" languagecode="2052" />
</labels>
<control id="notescontrol" classid="{06375649-c143-495e-a496-c962e5b4488e}" />
</cell>
</row>
<row />
<row />
<row />
<row height="auto" />
</rows>
</section>
</sections>
</tab>
6. 在EntityRelationships節點裡面添加一個新的關系,XML如下:
<EntityRelationship Name="new_noattachment_Annotations">
<EntityRelationshipType>OneToMany</EntityRelationshipType>
<ReferencingEntityName>Annotation</ReferencingEntityName>
<ReferencedEntityName>new_noattachment</ReferencedEntityName>
<CascadeAssign>Cascade</CascadeAssign>
<CascadeDelete>Cascade</CascadeDelete>
<CascadeReparent>Cascade</CascadeReparent>
<CascadeShare>Cascade</CascadeShare>
<CascadeUnshare>Cascade</CascadeUnshare>
<ReferencingAttributeName>objectid</ReferencingAttributeName>
<RelationshipDescription>
<Descriptions>
<Description description="與注釋關聯的對象的唯一辨別符。" languagecode="2052" />
</Descriptions>
</RelationshipDescription>
<field name="objectid" requiredlevel="none" imemode="auto" lookupstyle="single" lookupbrowse="0">
<displaynames>
<displayname description="關于" languagecode="2052" />
</displaynames>
</field>
</EntityRelationship>
7. 完成上面步驟之後将對應的CRM中的原有實體删除
8. 導入修改過的XML,導入成功之後釋出,檢視新導入的時候是否已經修改為可添加附件和注釋的實體。
我改動的方法大緻就是上面這樣,如果還有其他更好的方法請大家提出來共同學習
謝謝