Given an EntityType, such as \"Contact\", how can I derive from it the name of the EntitySet it would belong to, i.e. the pluralization such as \"Contacts\"?
Here is a method that works similar to the accepted answer except that this supports a) proxy types (for example, if you dynamically get the type of an EF6 entity it could be of type "Contact_1A2B3C4D5E" instead of "Contact") and b) inheritance (table-per-type, table-per-hierarchy).
private static string GetEntitySetName(ObjectContext objectContext, Type type)
{
if (objectContext == null) throw new ArgumentNullException(nameof(objectContext));
if (type == null) throw new ArgumentNullException(nameof(type));
EntityContainer container = objectContext.MetadataWorkspace.GetEntityContainer(objectContext.DefaultContainerName, DataSpace.CSpace);
return container.BaseEntitySets
.Where(x =>
(x.ElementType.Name == type.Name) ||
(x.ElementType.Name == type.BaseType?.Name) ||
(x.ElementType.Name == type.BaseType?.BaseType?.Name)
)
.Select(x => x.Name)
.FirstOrDefault() ?? throw new ArgumentException($"Specified type is not an entity type.", nameof(type));
}