Reputation: 139
So i have been learning Linq to SQL recently and I got it to query out record, but for the like of me, I couldn't figure out how to change the table's field. I really appreciate your help guys:
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);
}
}
Upvotes: 1
Views: 2564
Reputation: 223402
Just create an anonymous type like:
var ns = from nod in db.Nodes
where nod.Name == "MFMN"
select new
{
Identification = nod.NodeID,
//all other fields
};
and then:
foreach (var n in ns)
{
Console.WriteLine(n.Identification..... //rest of the fields
}
But, you have to specify all your fields that you need in your code. It is also useful when you only want to select specific columns and not all of the columns.
Upvotes: 1