Breeze.PocoMetadata.EntityDescriptor.IsKeyProperty C# (CSharp) Method

IsKeyProperty() public method

Determine if the property is part of the entity key.
public IsKeyProperty ( Type type, PropertyInfo propertyInfo ) : bool
type System.Type Entity type for which metadata is being generated
propertyInfo System.Reflection.PropertyInfo Property being considered
return bool
        public virtual bool IsKeyProperty(Type type, PropertyInfo propertyInfo)
        {
            var name = propertyInfo.Name;
            if (name == (type.Name + "ID")) return true;
            if (name == "ID") return true;
            return false;
        }

Usage Example

        /// <summary>
        /// Add the properties for an entity type.
        /// </summary>
        /// <param name="type">Type for which metadata is being generated</param>
        /// <param name="dataList">will be populated with the data properties of the entity</param>
        void AddDataProperties(Type type, List <Dictionary <string, object> > dataList)
        {
            // Get properties for the given class
            var propertyInfos = GetPropertyInfos(type);

            foreach (var propertyInfo in propertyInfos)
            {
                var elementType = GetElementType(propertyInfo.PropertyType);
                if (_entityTypes.Contains(elementType) || (_entityTypes.Contains(_describer.Replace(elementType, _allTypes))))
                {
                    // association to another entity in the metadata list; skip until later
                }
                else
                {
                    // data property
                    var isKey     = _describer.IsKeyProperty(type, propertyInfo);
                    var isVersion = _describer.IsVersionProperty(type, propertyInfo);

                    var dmap = MakeDataProperty(type, propertyInfo, isKey, isVersion);
                    if (dmap == null)
                    {
                        continue;               // excluded
                    }
                    dataList.Add(dmap);

                    // add enum types to the global enum list
                    var realType = propertyInfo.PropertyType;
                    var types    = propertyInfo.PropertyType.GetGenericArguments();
                    if (types.Length > 0)
                    {
                        realType = types[0];
                    }
                    if (realType.IsEnum)
                    {
                        if (!_enumList.Exists(x => x.ContainsValue(realType.Name)))
                        {
                            string[] enumNames = Enum.GetNames(realType);
                            var      p         = new Dictionary <string, object>();
                            p.Add("shortName", realType.Name);
                            p.Add("namespace", realType.Namespace);
                            p.Add("values", enumNames);
                            _enumList.Add(p);
                        }
                    }
                }
            }
        }