DataContext与实体类

// Define entity classes
[Table(Name = "CAR")]
public class CARclass
{
    [Column(Name = "Id")]
    public int Id { get; set; }
    [Column(Name = "Model")]
    public string Model { get; set; }
}

// Strongly typed DataContext
public partial class NorthWindDataContext : DataContext
{
    public Table<CARclass> CARs;
    public NorthWindDataContext(IDbConnection connection) : base(connection) { }
    public NorthWindDataContext(string connection) : base(connection) { }
}

static void Main(string[] args)
{
    NorthWindDataContext NWDC = new NorthWindDataContext(@"connection string");
    var NWCustomers = from NWs in NWDC.CARs
                        where NWs.Id == 1
                        select NWs;
    foreach (var cst in NWCustomers.ToList())
    {
        Console.WriteLine("Id = {0}, Model = {1}", cst.Id, cst.Model);
    }

    Console.ReadKey();
}
原文地址:https://www.cnblogs.com/jizhiqiliao/p/10736098.html