In some legacy projects at my work, I see a lot of using statements referring to the dbContext:
using (myContext dal = new myContext())
{
dal.DoSomeDatabaseThing
}
I believe this is fairly standard, and don't see a problem. In many places, however, I see something like this:
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(...)
{
sqlBulkCopy.DestinationTableName = myTable;
sqlBulkCopy.BatchSize = 10000;
}
Lo these many years, I've understood that the object referenced in a using statement is immutable. Indeed, MSDN docs state, "Within the using block, the object is read-only and cannot be modified or reassigned." Nevertheless, code blocks like the one above seem to work just fine.
What am I missing here? Clearly assigning values to an object's properties is modifying the object, no? I spoke to the team lead but he seemed unconcerned -- if it ain't broke, don't fix it -- kind of thing. But, it grates on me!
Any thoughts? Thanks