使用 LINQ to SQL 的示例
在 LINQ to SQL 中,您可以使用 LINQ 语法直接从关系数据库中查询数据。以下是一个查询客户信息的示例:
using System.Linq;
namespace LinqToSqlExample {
class Program {
static void Main(string[] args) {
// 创建一个 DataContext 对象
DataContext db = new DataContext("ConnectionString");
// 查询客户表中的所有客户
var customers = from customer in db.GetTable()
select customer;
// 遍历结果并显示每个客户的详细信息
foreach (var customer in customers) {
Console.WriteLine($"{customer.ID} - {customer.Name}");
}
}
}
}
926.78KB
文件大小:
评论区