예제 #1
0
    // This method returns the Summary Property
    public static IEntityPropertyDefinition GetSummaryProperty(
        IEntityType entityType)
    {
        ISummaryPropertyAttribute attribute =
            entityType.Attributes.OfType
            <ISummaryPropertyAttribute>().FirstOrDefault();

        if (attribute != null && attribute.Property != null)
        {
            return(attribute.Property);
        }

        // There's no Summary Property – return the first property
        return(GetFirstEntityProperty(entityType));
    }
예제 #2
0
        public static IEntityPropertyDefinition GetSummaryProperty(IEntityType entityType)
        {
            //Return the specified property if one is specified
            ISummaryPropertyAttribute attribute = entityType.Attributes.OfType <ISummaryPropertyAttribute>().FirstOrDefault();

            if (attribute != null && attribute.Property != null)
            {
                return(attribute.Property);
            }

            //If none is specified, try to infer one
            IEnumerable <IEntityPropertyDefinition> properties = entityType.Properties.Where(p => (!(p is INavigationPropertyDefinitionBase)) && (!p.PropertyType.Name.Contains("Binary")));
            IEntityPropertyDefinition stringProperty           = properties.FirstOrDefault(p => p.PropertyType.Name.Contains("String"));

            if (stringProperty == null)
            {
                return(properties.FirstOrDefault());
            }
            else
            {
                return(stringProperty);
            }
        }