Skip to content

Instantly share code, notes, and snippets.

@ekepes
Created February 20, 2012 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekepes/1870919 to your computer and use it in GitHub Desktop.
Save ekepes/1870919 to your computer and use it in GitHub Desktop.
Bad, bad, bad getter
public int SomeCountValue
{
get
{
if (_someCountValue == -1)
{
using (IUnitOfWork unitOfWork = new UnitOfWork())
{
_someCountValue = unitOfWork.GetQueryObjectInstance<ISomeQuery>()
.Where(Property1, Property2, Property3, Property4 ?? 0).Select();
}
}
return _someCountValue ;
}
}
@ekepes
Copy link
Author

ekepes commented Feb 20, 2012

A property getter should never do work. It ESPECIALLY should not make a call to the database. We have methods to do work. Code calling a property getter should be able to assume that the call takes a negligible amount of time - this is clearly not the case in this getter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment