c# - Inherit multiple base classes with the same inherited method-name -
Note: I am fairly new to the C # NET MVC and entity framework, and I am working on an existing project. In this project I have the following category:
Public category MyDbContext: DbContext, IMyDbContext {Public MyDbContext (): Base ("name = SQLAzureConnection") {} ... // Some IDbSet properties ... // some methods}
and the following interface:
Public Interface IMyDbContext {... // Some properties ... // something Revoke methods (); }
I use one of my methods:
using(using db = mvcApplication.dbContext (IMyDbContext)) { // usingDB} / code>
, I have modified my interface in the following:(
MvcApplication.dbContext ())
to be a representative (funk), which is instantaneously in my MvcApplication` like this:Public class MvcApplication: System.Web.HttpApplication {// to create a new IMyDbContext example public static Func & lt; IMyDbContext & gt; dbContext; public static MyDbContext dbContextInit () {new MyDbContext () ;} ... // Some other fields protected void Applica Tion_Start () {... dbContext = dbContextInit ();}}
I have this representative for short-term DbContext and my unit is capable of using it in the test.)
Since the object should be a disposable
Public interface IMIDBcontent: id isposable {.. .} Some properties ... // some methods (without); }
Everything works, except I get the following warning:
'MyNamespace.Model.IMyDbContext.Dispose ()' inherited member 'Hides System.IDisposable .Dispose ()'. If you intended to hide, then use the new keyword.
So that means I should use it:
New zero ();
instead ofzero ()
? The only reason I created it is that it can be used byIDisposable
so I can use it in. So I think the
new
-keyword is, so it will useDbContext.Dispose ()
? Or am I doing something wrong?I have also read that I can use
using
by using
, so I use DB while using. Dispos ()
in its ownend-case
. Nevertheless, I want to inherit myself fromIDisposable
instead of that option.
To get rid of your code, IDisposable
, then just change your interface to:
Public Interface IMyDbContext: IDisposable {... // some properties}
That's because you are already making your IMyDbContext
disposable already IDisposable
you do not need to explicitly add again . The compilation is warning you that you are doing a strange way without clearly telling users of two dissection
why
summary: just delete it and you Are golden!
Comments
Post a Comment