Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static async Task <PatientJournal> GetPatientJournalById(this AerendeContext context, Guid guid)
        {
            IIncludableQueryable <PatientJournal, Adress> patientJournal = context.GetChildrenInQuery();

            var singelPatientJournal = patientJournal.SingleOrDefaultAsync(x => x.Id == guid);

            return(await singelPatientJournal);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Finds an entity with the given id. If an entity with the given id
        ///     is being tracked by the context, then it is returned immediately without making a request to the
        ///     database. Otherwise, a query is made to the database for an entity with the given id
        ///     and this entity, if found, is returned. If no entity is found, then
        ///     null is returned. If <paramref name="tracked"/> is <see langword="true"/>,
        ///     then the entity is also attached to the context, so that subsequent calls can
        ///     return the tracked entity without a database roundtrip.
        /// </summary>
        /// <param name="id">The primary id of the entity.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
        /// <returns>The entity found, or null.</returns>
        /// <remarks>
        ///     This method is slightly faster than <see cref="DbSet{TEntity}.FindAsync(object[], CancellationToken)(object[])"/>
        ///     because the key is known.
        /// </remarks>
        public static ValueTask <TEntity> FindByIdAsync <TEntity, TProperty>(this IIncludableQueryable <TEntity, TProperty> query, int id, CancellationToken cancellationToken = default)
            where TEntity : BaseEntity
        {
            if (id == 0)
            {
                return(ValueTask.FromResult((TEntity)null));
            }

            var trackedEntity = FindTracked <TEntity>(query.GetDbContext(), id);

            return(trackedEntity != null
                ? new ValueTask <TEntity>(trackedEntity)
                : new ValueTask <TEntity>(
                       query.SingleOrDefaultAsync(x => x.Id == id, cancellationToken)));
        }