// This may seem strange, there can only be one entity per // id, but we still want to return an IQueryable in order // to respect deferred execution if it's required... // So therefore we still do a Where call, and then let // the caller execute a Single or SingleOrDefault after // doing a ProjectTo. Alternatively this also allows the // caller to perform a Select in order to filter the // properties in the entity, or perhaps create a different // DTO containing just one or a few of the properties. // This is particularly relevant for Entities that contain // a great many properties, and means the resulting query // on the database only SELECTs the fields that are actually // required, which is far more efficient than SELECTing the // entire row from the DB only to drop all but a few columns // when the Service populates a DTO. public virtual IQueryable <T> GetById(long id) { return(Context.Set <T>().Where(x => x.Id == id)); }