Example #1
0
        protected bool TryAllKeysDefault(TEntity entity)
        {
            if (_container.IsIEntity <TEntity, TPrimaryKey>())
            {
                if (entity is IEntity <TPrimaryKey> entityInterface)
                {
                    return(entityInterface.Id.CompareTo(default(TPrimaryKey)) == 0);
                }
            }

            var keys       = _container.GetKeys <TEntity>();
            var properties = _container.GetProperties <TEntity>(keys);

            if (keys == null || properties == null)
            {
                throw new NoPkException(
                          "There is no keys for this entity, please create your logic or add a key attribute to the entity");
            }
            return(properties.Select(property => property.GetValue(entity)).All(value => value == null || value.Equals(default(TPrimaryKey))));
        }