所以我最近一直在学习Linq to SQL,我得到它来查询记录,但就我而言,我无法弄清楚如何更改表格的字段。我真的很感谢你们的帮助:
using (var db = new DataClasses1DataContext())
{
var ns = from nod in db.Nodes
where nod.Name == "MFMN"
select nod;
int pop = db.Nodes.Count();
foreach (var n in ns)
{
Console.WriteLine(n.NodeID + " " + n.lkpNodeType + " " + n.Name + " " + n.DeploymentID);
}
}
答案 0 :(得分:1)
只需创建一个anonymous type,如:
var ns = from nod in db.Nodes
where nod.Name == "MFMN"
select new
{
Identification = nod.NodeID,
//all other fields
};
然后:
foreach (var n in ns)
{
Console.WriteLine(n.Identification..... //rest of the fields
}
但是,您必须在代码中指定所需的所有字段。当您只想选择特定列而不是所有列时,它也很有用。