Aras学习笔记 (35) 根据Source Id提取关联Related Item列表的通用方法

在操作Aras Item时经常需要根据Source Item Id来提取Related Item列表,实际上两个ItemType之间的关系是通过Relationship来实现,关系结构如下图。

通用方法为:

/// <summary>
/// 根据Source Id获取Related Item List
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="SourceItemTypeName"></param>
/// <param name="RelationshipItemTypeName"></param>
/// <param name="RelatedItemTypeName"></param>
/// <param name="SourceId"></param>
/// <returns></returns>
public List<T> GetListBySourceId<T>(string SourceItemTypeName, string RelationshipItemTypeName, string RelatedItemTypeName, string SourceId)
{
	List<T> list = new List<T>();

	string aml = @"<AML>
                                <Item type='{0}' action='get'>
                                    <related_id>
                                        <Item type='{1}' action='get'>
                                        </Item>
                                    </related_id>
                                    <source_id>
                                        <Item type='{2}' action='get'>
                                            <id>{3}</id>
                                        </Item>
                                    </source_id>
                                </Item>
                           </AML>";

	if (innovator != null)
	{
		Item item = innovator.applyAML(string.Format(aml, RelationshipItemTypeName, RelatedItemTypeName, SourceItemTypeName, SourceId));
                if (item != null)
                {
                    if (item.node != null || item.nodeList != null)
                    {
                        ModelHelper helper = new ModelHelper();
                        list = helper.GetModelListFromXml<T>(item.dom.InnerXml, "related_id");
                    }
                }
	}

     return list;
}
原文地址:https://www.cnblogs.com/61007257Steven/p/10255591.html