Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LINQ DataContext and IDisposable

LINQ DataContext and IDisposable

Scheduled Pinned Locked Moved C#
csharpdatabaselinqhelpquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3919049
    wrote on last edited by
    #1

    Hi - I'm implementing a data access layer in LINQ to SQL. I have a DataContext MyDataContext which extends DataContext. DataContext implements IDisposable. However when I try to put MyDataContext in a using statement I get a compiler error: 'MyDataContext':type used in a using statement must be implicitly convertible to 'System.IDisposable'. So is IDisposable not implicitly usable for derived classes or am I doing something wrong? Here is some sample code: using (MyDataContext context = new MyDataContext()) { //do some work }

    P 1 Reply Last reply
    0
    • M Member 3919049

      Hi - I'm implementing a data access layer in LINQ to SQL. I have a DataContext MyDataContext which extends DataContext. DataContext implements IDisposable. However when I try to put MyDataContext in a using statement I get a compiler error: 'MyDataContext':type used in a using statement must be implicitly convertible to 'System.IDisposable'. So is IDisposable not implicitly usable for derived classes or am I doing something wrong? Here is some sample code: using (MyDataContext context = new MyDataContext()) { //do some work }

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      If your class inherits from DataContext, you get IDisposable for free. Could you post your class definition here so that we can take a look at it?

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups