linqpad - SubmitChanges 扩展
是否可以让 SubmitChanges() 在扩展方法中工作?
我目前有这个:
void Main()
{
// Write code to test your extensions here. Press F5 to compile and run.
Helper.ConfirmSubmitChanges();
}
public static class Helper
{
// Write custom extension methods here. They will be available to all queries.
public static void ConfirmSubmitChanges()
{
if (MessageBox.Show("Save?", "Do you really want to save all changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
SubmitChanges();
}
}
}
// You can also define non-static classes, enums, etc.
但是 SubmitChanges() 在这里脱离了上下文。我可以从我的查询中传递什么内容来使用此扩展来使其工作吗?
谢谢, 科汉
Is it possible to get SubmitChanges() to work from within an extension method?
I currently have this:
void Main()
{
// Write code to test your extensions here. Press F5 to compile and run.
Helper.ConfirmSubmitChanges();
}
public static class Helper
{
// Write custom extension methods here. They will be available to all queries.
public static void ConfirmSubmitChanges()
{
if (MessageBox.Show("Save?", "Do you really want to save all changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
SubmitChanges();
}
}
}
// You can also define non-static classes, enums, etc.
But SubmitChanges() is out of context here. Is there anything that i can pass it from my queries that will use this extension to make it work?
Thanks,
Kohan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过将当前上下文 (
this
) 传递到静态方法中来完成此操作:您的程序:
在 My Extensions.linq 中:
You can do it with the by passing the current Context (
this
) into the static method:Your program:
In My Extensions.linq:
如果有人想知道,请将“this”传递给扩展程序后。这就是我最终创建的。这很好,因为它还确认了更改的数量。
In case anyone wants to know, after passing "this" to the Extension. This is what i created in the end. It's nice because it also confirms the number of changes.