EF Core equivalent of ObjectContext.MetadataWorkspace

Viewed 70

We previously (i.e., in EF 6) used the following code to obtain all enum properties which are used in any entity or complex type in our EF model:

var metadataWorkspace = ((IObjectContextAdapter) context).ObjectContext.MetadataWorkspace;
var enumTypes = metadataWorkspace
                 .GetItems<StructuralType>(DataSpace.OSpace)
                 .SelectMany(t => t.Members)
                 .OfType<EdmProperty>()
                 .Where(m => m.EnumType != null)
                 .Select(m => m.EnumType)
                 .Distinct()
                 .ToList();

What is the EF Core equivalent of this? How to access "all types" in the model?

Is the following correct and complete (i.e., not missing owned types or anything like that).

var enumTypes = context.Model.GetEntityTypes()
                 .SelectMany(et => et.GetProperties())
                 .Where(p => p.ClrType.IsEnum)
                 .Distinct()
                 .ToList();
0 Answers
Related