Created
February 22, 2013 09:04
-
-
Save Spaider/5011922 to your computer and use it in GitHub Desktop.
Shows how to work with DB instances in custom data accessors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Accessor for working with Stuff | |
/// </summary> | |
public static class SampleDataAccessor | |
{ | |
/// <summary> | |
/// This overload opens DB connection and thus, manages DB state. | |
/// Wrapping creation in using clause ensures that it will be | |
/// properly disposed | |
/// </summary> | |
public static void SaveStuff(Stuff stuff) | |
{ | |
using(var db = new AthlinksDB()) | |
{ | |
db.BeginTransaction(); | |
SaveStuff(db, stuff); | |
db.CommitTransaction(); | |
} | |
} | |
/// <summary> | |
/// This overload receive DB instances and thus does not try | |
/// to manage its state, just does actual work. | |
/// Possible exceptions will be passed upwards | |
/// </summary> | |
public static void SaveStuff(AthlinksDB db, Stuff stuff) | |
{ | |
// Save stuff actually | |
... | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment