entity framework - C# Generic Method T Class T Override -


in c# have generic class looks this:

public class datamanager<t> : idisposable t : class 

that used this:

    public t getbyid(string id)     {         return this.context.set<t>().find(id);     } 

this works great.

however if have 2 types in manager, in case, ticket , ticketresponse, able override type without having add type every method call. this:

    public t getbyid<t>(string id) t : class     {         return this.context.set<t>().find(id);     } 

where can call interchangeably so:

    var ticket = getbyid(myid);     var ticketresponse = getbyid<ticketresponse>(myid); // override 

the idea not have create separate manager sub-object, not have entire ticket have iterate through responses, able directly.

is possible?

you try this:

public t getbyid( string id ) {     return getbyid<t>( id ); }  public u getbyid<u>( string id ) u : t {     return this.context.set<u>().find( id ); } 

so have original method additional generic method can take parameter type derives t.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -