-5

My code has an error, I do not know what is causing it

namespace cms.data.System
{
    public class MenuProccess
    {
        public static List<ModelMenu> GetMenus(Nullable<int> LanguageID){

        using (cmsEntities db = new cmsEntities) //error on this line
        {
            return null;
        }

        return null;
    }
}

the error is

'cmsEntities': Type used in a using statement must be implicitly convertible to 'System.IDisposable'

Alfie Goodacre
  • 2,753
  • 1
  • 13
  • 26
Oğuzhan Sari
  • 89
  • 1
  • 9
  • 2
    cmsEntities does not implement `System.IDisposable` – Tim B James Nov 08 '16 at 16:11
  • If cmsEntities is derived from DataContext then see [this question](http://stackoverflow.com/questions/12508031/entity-framework-5-model-first-where-is-idisposable-gone) _"… your problem is most likely that your model is defined in a separate assembly that references EF5 and you have not added an EF5 reference to your project"_ – stuartd Nov 08 '16 at 16:15
  • `Nullable` is replaceable with `int?` by the way! – Alfie Goodacre Nov 08 '16 at 16:31

3 Answers3

3

When we use a using statement

using(var a = new ClassName())
{

}

the ClassName or whatever class you use there should implement the IDisposable interface. That being said, it's obvious that cmsEntities doesn't implement this interface.

Christos
  • 53,228
  • 8
  • 76
  • 108
2

The cmsEntities class must be implement IDisposable interface for use of "using" statement.

Fabio Silva Lima
  • 704
  • 6
  • 14
0

The problem may be the project name change.

I sat and I cried. I created a new project. I started again. Thank God I started the project today. I did not go too far.

Thank you :)

Oğuzhan Sari
  • 89
  • 1
  • 9