示例#1
0
        public static bool IsPersistent(DomainObject entity)
        {
            var isPersistent = true;
            var keys = GetPrimaryKeys(entity);
            foreach (var key in keys)
            {
                isPersistent = isPersistent && !(key.Value.ToString().Equals(string.Empty) || key.Value.ToString().Equals("0"));
            }

            return isPersistent;
        }
示例#2
0
 public static Dictionary<string, object> GetPrimaryKeys(DomainObject entity)
 {
     var properties = entity.GetType().GetProperties();
     var keys = new Dictionary<string, object>();
     foreach (var property in properties)
     {
         var attribute = Attribute.GetCustomAttribute(property, typeof(KeyAttribute)) as KeyAttribute;
         if (attribute != null)
         {
             keys.Add(property.Name, property.GetValue(entity));
         }
     }
     return keys;
 }