none
How do you get EntityType from EdmMember/EdmProperty? RRS feed

  • Question

  • I am trying to get the EntityType from the EdmMember or EdmProperty. The closest I have come is:

    edmproperty.DeclaringType.Name
    
    || 
    
    edmmember.DeclaringType.Name


    The problem with using the DeclaringType is that it does not have the plural version of the name in order to look up the EntityType by name.  See look up below:

            public EntityType GetEntityType(String entityCollectionName)
            {
                foreach (EntityType entityType in GetEntityTypes())
                {
                    if (entityCollectionName.Equals(entityType.Name))
                    {
    
                        return entityType;
                    }
                }
                return null;
            }
    
            public IEnumerable<EntityType> GetEntityTypes()
            {
                ObjectContext objContext = ((IObjectContextAdapter)this).ObjectContext;
                MetadataWorkspace ws = objContext.MetadataWorkspace;
                IEnumerable<EntityType> entities = ws.GetItems<EntityType>(DataSpace.SSpace);
                return entities;
            }

    For example if I wanted the Student EntityType, I would call GetEntityType("Students") or

    if I wanted the "Class" EntityType, I would call GetEntityType("Classes") or

    if I wanted the "ClassHistory" EntityType, I would call GetEntityType("ClassHistories").

    This would cause some ugly code in order to convert the name to its plural EntityType name.

    Is there a way to get the pluralized version of the name from the edmmember/edmproperty, or change the Entity lookup to do it by the singular version of the name?


    • Edited by Catequil Tuesday, February 11, 2014 1:14 AM clarification
    Tuesday, February 11, 2014 1:11 AM

Answers

  • Hello,

    >>Is there a way to get the pluralized version of the name from the edmmember/edmproperty, or change the Entity lookup to do it by the singular version of the name?

    The pluralized version of the name of the entities classes is stored in EntityContainer, we can them as below:

    EntityContainer container = objContext.MetadataWorkspace.GetEntityContainer(objContext.DefaultContainerName, DataSpace.CSpace);
    

    The result:

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 11, 2014 7:33 AM
    Moderator