Esempio n. 1
0
        /// <summary>
        /// Gets the value of the primary key property on a given object based on a Schema
        /// </summary>
        /// <param name="obj">The object to get the property value of the primary key from</param>
        /// <param name="Schema">The schema to check the primary key against</param>
        /// <returns><see cref="null"/> if the given object's primary key is the value of <see cref="null"/></returns>
        public static object GetPrimaryKeyValue(this DBSchema Schema, object obj)
        {
            foreach (var prop in obj.GetType().GetProperties())
            {
                if (Schema.IsPrimaryKey(prop, obj.GetType()))
                {
                    return(prop.GetValue(obj));
                }
            }

            // Should never be reached
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets wether the value of the primary key of the given object is set based on a schema
        /// </summary>
        /// <param name="obj">The object to check</param>
        /// <param name="Schema">The schema to check against</param>
        /// <returns></returns>
        public static bool HasPrimaryKeyValue(this DBSchema Schema, object obj)
        {
            foreach (var prop in obj.GetType().GetProperties())
            {
                if (Schema.IsPrimaryKey(prop, obj.GetType()))
                {
                    if (prop.GetValue(obj) != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }