Beispiel #1
0
 public void Dispose()
 {
     if (_context != null && _ownContext)
     {
         _context.Dispose();
     }
 }
    public static FooObject GetFooObject(int FooID, MyDB db)
    {
        bool closeFlag = false;

        //if null was passed in, then we will create our own connection and manage it
        if (db == null)
        {
            _db       = new MyDB();
            closeFlag = true;
        }
        else
        {
            //otherwise, we set our local variable
            _db = db;
        }
        //from now on, all queries are done using the local variable
        var _f = _db.Foos
                 .Include("x")
                 .Include("y")
                 .Include("z")
                 .SingleOrDefault(f => f.FooID == FooID);
        var fo = FooObjectFromFoo(_f, db);

        if (closeFlag)
        {
            db.Dispose();
        }
        return(fo);
    }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }