[英]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. 我已经尝试了类似“ c#ef对象集扩展方法”之类的Googling字符串,但是我想我在这里使用了错误的术语,因为我找不到任何相关的东西。
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. 我认为有很多SO线程可以解决这个问题,但是我找不到它们。
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 这是有关扩展方法的 MSDN文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.