/// <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> /// <returns>The entity found, or null.</returns> /// <remarks> /// This method is slightly faster than <see cref="DbSet{TEntity}.Find(object[])"/> /// because the key is known. /// </remarks> public static TEntity FindById <TEntity, TProperty>(this IIncludableQueryable <TEntity, TProperty> query, int id) where TEntity : BaseEntity { if (id == 0) { return(null); } return(FindTracked <TEntity>(query.GetDbContext(), id) ?? query.SingleOrDefault(x => x.Id == id)); }
public Calendar Get(string year) => _calendars.SingleOrDefault(c => c.SchoolYear == year);