在Mono上使用Linq和MySql数据库,您需要遵循以下步骤:
using System;
using System.Linq;
using MySql.Data.MySqlClient;
namespace MonoMySqlLinq
{
class Program
{
static void Main(string[] args)
{
string connectionString = "Server=localhost;Database=mydatabase;Uid=myusername;Pwd=mypassword;";
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
var query = from customer in connection.Query<Customer>("SELECT * FROM customers")
where customer.City == "New York"
select customer;
foreach (var customer in query)
{
Console.WriteLine($"Customer Name: {customer.Name}, City: {customer.City}");
}
connection.Close();
}
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
}
}
在这个示例中,我们使用Linq查询从MySql数据库中获取所有位于纽约市的客户,并将结果打印到控制台。
推荐的腾讯云相关产品:
产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云