Exemple #1
0
 private void ThrowIfModelHasInvalidId(TModel model)
 {
     if (false == _modelId.Equals(model.Id))
     {
         throw new InvalidOperationException(
                   "Model id is invalid."
                   + $"{NewLine} The expected value: {_modelId}"
                   + $"{NewLine} The actual value: {model.Id}");
     }
 }
            /// <inheritdoc />
            public override bool Equals(object obj)
            {
                if (ReferenceEquals(obj, null))
                {
                    return(false);
                }
                if (!(obj is CompositeKey other))
                {
                    return(false);
                }

                return(Id?.Equals(other.Id) == true &&
                       Name?.Equals(other.Name) == true);
            }
        public virtual TId GetNextId <TEntity, TId>() where TEntity : IEntity <TId>
        {
            Type entityType = typeof(TEntity);

            SequenceAttribute attribute = entityType.GetCustomAttribute <SequenceAttribute>();

            if (attribute == null)
            {
                throw new InvalidOperationException("You need to decorate your entity with Sequence attribute to use this extension method.");
            }

            string sequenceName = attribute.Name;

            DbRawSqlQuery <TId> result = Database.SqlQuery <TId>($"SELECT (NEXT VALUE FOR {sequenceName})");

            TId id = result.FirstOrDefault();

            if (id == null || id.Equals(default(TId)))
            {
                throw new InvalidOperationException($"Database did not return an instance of identity for sequence {sequenceName}.");
            }

            return(id);
        }