如何使LINQ to SQL结果成为一个全局变量 [英] how to make LINQ to SQL result become a global variable
本文介绍了如何使LINQ to SQL结果成为一个全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class Form1:Form |
{ |
< font style ="color:blue; font-size:14px"> public Form1() |
{ |
InitializeComponent(); |
} |
private void button1_Click( object sender,EventArgs e) |
{ |
Common.NorwindDataContext context = new NorwindDataContext(); |
var results = context .Suppliers.GroupJoin(context.Products,c => c.SupplierID,d => d.SupplierID,(a,b)=> new {supplier = a.CompanyName,products = b}); |
} |
} 结果是一个局部变量,但现在,我希望它成为一个全局变量,请帮助我。 感谢帮助 < br> |
public partial class Form1 : Form |
{ |
public Form1() |
{ |
InitializeComponent(); |
} |
private void button1_Click(object sender, EventArgs e) |
{ |
Common.NorwindDataContext context = new NorwindDataContext(); |
var results = context.Suppliers.GroupJoin(context.Products, c => c.SupplierID, d => d.SupplierID, (a, b) => new { supplier = a.CompanyName, products = b }); |
} |
} results is a local variable, but now, i want it become a global variable, please help me. thank for help |
推荐答案
如果您的新结果属于同一类型,那么您可以组成由供应商和产品组成的类,并在全球范围内使用其对象。
If your new results will be of same type then you may make a class comprising of Supplier and Products as it's member and use its object globally.
这篇关于如何使LINQ to SQL结果成为一个全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文