2
我一直在嘗試編寫一些通用代碼來創建Habanero業務對象的xml包。該代碼當前可以處理組合關係,但我需要手動添加關聯關係。有沒有什麼方法可以通過更通用的方式添加沒有複合反向關係的關聯關係。Habanero中的關係
這是組合關係是如何加入
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);
}
}
感謝@GloryDev,我會檢查出代碼這個週末,看看它的伎倆。 – Andrew 2011-05-27 14:34:14