gpt4 book ai didi

c# - 哈瓦那人的关系

转载 作者:太空宇宙 更新时间:2023-11-03 11:36:22 25 4
gpt4 key购买 nike

我一直在尝试编写一些通用代码来创建 Habanero 业务对象的 xml 包。该代码目前可以处理组合关系,但我需要手动添加关联关系。有什么方法可以以更通用的方式添加没有复合反向关系的关联关系。

组合关系是这样加起来的

    private static void AddRelatedCompositionObjects(Package package, IBusinessObject businessObject)
{
businessObject.Relationships
.Where(rel => rel.RelationshipType == RelationshipType.Composition)
.Where(rel => rel is IMultipleRelationship)
.Select(rel => (IMultipleRelationship)rel)
.ForEach(rel => rel.BusinessObjectCollection
.AsEnumerable<IBusinessObject>()
//.ForEach(package.Add));
.ForEach(bo => BuildPackage(package, bo)));

businessObject.Relationships
.Where(rel => rel.RelationshipType == RelationshipType.Composition)
.Where(rel => rel is ISingleRelationship)
.Select(rel => (ISingleRelationship)rel)
//.ForEach(rel => package.Add(rel.GetRelatedObject()));
.ForEach(rel => BuildPackage(package, rel.GetRelatedObject()));
}

然后我手动添加关联关系

                var package = new Package();
foreach (var returnDelivery in returnDeliveries)
{
package.Add(returnDelivery);
if (returnDelivery != null)
{
var materials = returnDelivery.DeliveryItems.Select(item => item.Material).Distinct();
materials.ToList().ForEach(material =>
{
package.Add(material);
material.EWTMaterials.ForEach(package.Add);
});
package.Add(returnDelivery.Customer);
}
}

最佳答案

首先要意识到的是1)Habanero 不需要你定义反向关系。尽管如果您从 Firestarter 生成您的类定义,您将拥有一个。

我从 Habanero.BO 的 ClassDefValidator 中窃取了这个示例片段,因此它可能不是您想要的,当然可以推广到架构中。这段代码的作用是获取 relationshipDef 的反向 relationshipDef

此代码在 Habanero.BO.ClassDefValidator 中

CheckRelationshipsForAClassDef 方法如果您查看此处,您将看到获取 relatedClassDef 的代码。将其转换成您需要的东西应该很容易。

如果你有任何问题,请告诉我。

        if (!HasReverseRelationship(relationshipDef)) return;

string reverseRelationshipName = relationshipDef.ReverseRelationshipName;
if (!relatedClassDef.RelationshipDefCol.Contains(reverseRelationshipName))
{
throw new InvalidXmlDefinitionException
(string.Format
("The relationship '{0}' could not be loaded for because the reverse relationship '{1}' defined for class '{2}' is not defined as a relationship for class '{2}'. Please check your ClassDefs.xml or fix in Firestarter.",
relationshipDef.RelationshipName, reverseRelationshipName, relatedClassDef.ClassNameFull));
}

var reverseRelationshipDef = relatedClassDef.RelationshipDefCol[reverseRelationshipName];

布雷特

关于c# - 哈瓦那人的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6153263/

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