Пример #1
0
        /// <summary>
        /// Copy new object by identity
        /// </summary>
        /// <returns>Return a new entity object</returns>
        public T CopyOnlyWithIdentity()
        {
            var newData     = new T();
            var primaryKeys = EntityManager.GetPrimaryKeys <T>();

            if (primaryKeys.IsNullOrEmpty())
            {
                return(newData);
            }
            foreach (var key in primaryKeys)
            {
                var value = GetValue(key);
                newData.SetValue(key, value);
            }
            return(newData);
        }
Пример #2
0
        /// <summary>
        /// Gets the object primary key value
        /// </summary>
        /// <returns>Return the primary key values</returns>
        internal Dictionary <string, dynamic> GetPrimaryKeyValues()
        {
            var primaryKeys = EntityManager.GetPrimaryKeys(typeof(T));
            var keysCount   = primaryKeys.GetCount();

            if (primaryKeys == null || keysCount <= 0)
            {
                return(new Dictionary <string, dynamic>(0));
            }
            Dictionary <string, dynamic> values = new Dictionary <string, dynamic>(keysCount);

            foreach (var key in primaryKeys)
            {
                values.Add(key, GetValue(key));
            }
            return(values);
        }
Пример #3
0
        /// <summary>
        /// copy new by identity
        /// </summary>
        /// <returns></returns>
        public T CopyNewByIdentity()
        {
            var newData = (T)this.DeepClone();

            newData.valueDict.Clear();
            var primaryKeys = EntityManager.GetPrimaryKeys <T>();

            if (primaryKeys.IsNullOrEmpty())
            {
                return(newData);
            }
            foreach (var pk in primaryKeys)
            {
                var value = GetPropertyValue(pk.PropertyName);
                newData.SetPropertyValue(pk.PropertyName, value);
            }
            return(newData);
        }
Пример #4
0
        /// <summary>
        /// get object primary key value
        /// </summary>
        /// <returns></returns>
        internal Dictionary <string, dynamic> GetPrimaryKeyValues()
        {
            var primaryKeys = EntityManager.GetPrimaryKeys(typeof(T));

            if (primaryKeys == null || primaryKeys.Count <= 0)
            {
                return(new Dictionary <string, dynamic>(0));
            }
            Dictionary <string, dynamic> values = new Dictionary <string, dynamic>(primaryKeys.Count);

            foreach (var key in primaryKeys)
            {
                if (valueDict.ContainsKey(key))
                {
                    values.Add(key, valueDict[key]);
                }
            }
            return(values);
        }
Пример #5
0
        /// <summary>
        /// get primary keys with cache
        /// </summary>
        /// <returns></returns>
        public string GetPrimaryCacheKey(bool includeObjectName = true)
        {
            List <EntityField> primaryKeys = EntityManager.GetPrimaryKeys(typeof(T));

            return(GenerateCacheKey(primaryKeys, includeObjectName));
        }