Use LINQ to SQL : SQL : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » SQL »

 

Use LINQ to SQL








    
 
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);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» SQL