Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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