Skip to content

Commit

Permalink
Fixed exposing optionset metadata and handle null values
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Dec 9, 2024
1 parent 6b305de commit d7e24f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/MetadataQueryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ protected override IEnumerable<Entity> ExecuteInternal(NodeExecutionContext cont
if (MetadataSource.HasFlag(MetadataSource.Value))
{
results = results
.Where(r => r.Attribute is EnumAttributeMetadata)
.Where(r => r.Attribute is EnumAttributeMetadata a && a.OptionSet != null)
.SelectMany(r => ((EnumAttributeMetadata)r.Attribute).OptionSet.Options.Select(o => new { Entity = r.Entity, Attribute = r.Attribute, Relationship = r.Relationship, Key = r.Key, Value = o }))
.Concat(
results
Expand All @@ -1164,7 +1164,8 @@ protected override IEnumerable<Entity> ExecuteInternal(NodeExecutionContext cont
new { Entity = r.Entity, Attribute = r.Attribute, Relationship = r.Relationship, Key = r.Key, Value = ((BooleanAttributeMetadata)r.Attribute).OptionSet.FalseOption },
new { Entity = r.Entity, Attribute = r.Attribute, Relationship = r.Relationship, Key = r.Key, Value = ((BooleanAttributeMetadata)r.Attribute).OptionSet.TrueOption },
})
);
)
.Where(r => r.Value != null);
}

foreach (var result in results)
Expand Down
3 changes: 2 additions & 1 deletion MarkMpn.Sql4Cds.Engine/MetaMetadataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static MetaMetadataCache()

// Reuse the schema exposed by the nodes that actually execute the metadata queries
var metadataNode = new MetadataQueryNode();
metadataNode.MetadataSource = MetadataSource.Entity | MetadataSource.Attribute | MetadataSource.OneToManyRelationship | MetadataSource.ManyToOneRelationship | MetadataSource.ManyToManyRelationship | MetadataSource.Key;
metadataNode.MetadataSource = MetadataSource.Entity | MetadataSource.Attribute | MetadataSource.OneToManyRelationship | MetadataSource.ManyToOneRelationship | MetadataSource.ManyToManyRelationship | MetadataSource.Key | MetadataSource.Value;
metadataNode.EntityAlias = "entity";
metadataNode.AttributeAlias = "attribute";
metadataNode.OneToManyRelationshipAlias = "relationship_1_n";
Expand All @@ -109,6 +109,7 @@ static MetaMetadataCache()
_customMetadata["metadata." + metadataNode.ValueAlias] = SchemaToMetadata(metadataSchema, metadataNode.ValueAlias);

var optionsetNode = new GlobalOptionSetQueryNode();
optionsetNode.MetadataSource = OptionSetSource.OptionSet | OptionSetSource.Value;
optionsetNode.OptionSetAlias = "globaloptionset";
optionsetNode.ValueAlias = "globaloptionsetvalue";

Expand Down

0 comments on commit d7e24f2

Please sign in to comment.