Csharp/C Sharp by API/System.Data.Linq/DataContext — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 15:11, 26 мая 2010
new DataContext
<source lang="csharp"> using System; using System.Linq; using System.Data.Linq; using System.Data.Linq.Mapping; static class HelloLinqToSql {
[Table(Name = "Contacts")] class Contact { [Column(IsPrimaryKey = true)] public int ContactID { get; set; } [Column(Name = "ContactName")] public string Name { get; set; } [Column] public string City { get; set; } } static void Main() { string path = System.IO.Path.GetFullPath("northwnd.mdf"); DataContext db = new DataContext(path); var contacts = from contact in db.GetTable<Contact>() where contact.City == "Paris" select contact; foreach (var contact in contacts) Console.WriteLine("Bonjour " + contact.Name); }
}
</source>