Linq To Sql : DataSet « LINQ « C# / CSharp Tutorial






using System;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;

    [Table]
    public class Customers
    {
        [Column]
        public string customerId;
        [Column]
        public string companyName;
        [Column]
        public string city;
        [Column]
        public string country;
    }

    class LinqToSql
    {
        static void Main(string[] args)
        {
            string connString = @"server = .\sqlexpress;integrated security = true;database = northwind";
            DataContext db = new DataContext(connString);
            Table<Customers> customers = db.GetTable<Customers>();
            var custs = from c in customers where c.country == "USA" orderby c.city select c;
            foreach (var c in custs)
                Console.WriteLine(
                   "{0}, {1}, {2}, {3}",
                   c.customerId,
                   c.companyName,
                   c.city,
                   c.country
                );
        }
    }








22.78.DataSet
22.78.1.LINQ to DataSet
22.78.2.Simple Linq to SQL
22.78.3.Linq To Sql