Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
EF6 assembly import done; associations work well
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSawczyn-AWH committed Dec 26, 2019
1 parent 2233931 commit 83325e5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3,732 deletions.
29 changes: 17 additions & 12 deletions src/Dsl/CustomCode/Utilities/Import/AssemblyProcessor.cs
Expand Up @@ -123,20 +123,25 @@ private void ProcessClasses(ModelRoot modelRoot, List<ParsingModels.ModelClass>
ProcessProperties(element, data.Properties);
}

// Bidirectional associations can get duplicates creeping in, and it's better to clean them here than to rely on each parser version
foreach (ParsingModels.ModelClass modelClass in classDataList)
// Bidirectional associations get duplicates, and it's better to clean them here than to rely on each parser version
List<ModelBidirectionalAssociation> allBidirectionalAssociations = classDataList.SelectMany(cls => cls.BidirectionalAssociations).ToList();

for (int index = 0; index < allBidirectionalAssociations.Count; index++)
{
foreach (ModelBidirectionalAssociation association in modelClass.BidirectionalAssociations)
ModelBidirectionalAssociation keeper = allBidirectionalAssociations[index];

ModelBidirectionalAssociation duplicate =
allBidirectionalAssociations.Skip(index)
.FirstOrDefault(a => a.SourcePropertyTypeName == keeper.TargetPropertyTypeName
&& a.SourcePropertyName == keeper.TargetPropertyName
&& a.TargetPropertyTypeName == keeper.SourcePropertyTypeName
&& a.TargetPropertyName == keeper.SourcePropertyName);

if (duplicate != null)
{
ModelBidirectionalAssociation[] duplicates = modelClass.BidirectionalAssociations
.Where(a => a.SourcePropertyTypeName == association.TargetPropertyTypeName
&& a.SourcePropertyName == association.TargetPropertyName
&& a.TargetPropertyTypeName == association.SourcePropertyTypeName
&& a.TargetPropertyName == association.SourcePropertyName)
.ToArray();

foreach (ModelBidirectionalAssociation duplicate in duplicates)
modelClass.BidirectionalAssociations.Remove(duplicate);
ParsingModels.ModelClass duplicateOwner = classDataList.First(c=>c.FullName==duplicate.SourceClassFullName);
duplicateOwner.BidirectionalAssociations.Remove(duplicate);
allBidirectionalAssociations.Remove(duplicate);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DslPackage/CustomCode/Partials/EFModelDocData.cs
Expand Up @@ -274,7 +274,7 @@ private void ValidateModelElement(ModelElement modelElement)
{
if (!ModelRoot.BatchUpdating && modelElement is IDisplaysWarning displaysWarningElement)
{
StatusDisplay.Show($"Validating {modelElement}");
StatusDisplay.Show($"Validating {modelElement.GetDisplayText()}");
displaysWarningElement.ResetWarning();

ValidationCategories allCategories = ValidationCategories.Menu | ValidationCategories.Open | ValidationCategories.Save | ValidationCategories.Custom | ValidationCategories.Load;
Expand Down
3 changes: 1 addition & 2 deletions src/Testing/Sandbox_EF6/IncludeContext.cs
@@ -1,2 +1 @@



0 comments on commit 83325e5

Please sign in to comment.