简体   繁体   中英

Custom objectset extension methods

I have tried Googling strings like "c# ef objectset extension methods" but I suppose I'm using the wrong terms here, because I can't find anything relevant.

What I would like to know is how I add a custom extenstionmethod that I can use on my database context:

context.TABLE.MyMethod(...

I assume that there are a lot of SO threads covering this, but I can't find them.

public static class YourExtensions
{
    public static void MyMethod<T>(this DbSet<T> table)
       where T: class // this constraint is required because DbSet<T> have it
    {
        // code here
    }
}

Here is MSDN article on Extension Methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM