{"id":115,"date":"2010-10-11T21:06:47","date_gmt":"2010-10-12T01:06:47","guid":{"rendered":"http:\/\/wukenny.host-ed.net\/?p=115"},"modified":"2010-10-11T21:06:47","modified_gmt":"2010-10-12T01:06:47","slug":"linq-to-sql-1","status":"publish","type":"post","link":"http:\/\/kennywu.info\/?p=115","title":{"rendered":"Linq to SQL (1)"},"content":{"rendered":"<p>You can crate a Plain Old CLR Object to map the underlining database table w\/o the help of the LINQ-to-SQL designer. To represent a customer class, you need the following code. <\/p>\n<pre lang=\"csharp\">\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Data.Linq;\nusing System.Data.Linq.Mapping;\nusing System.Text;\n\nnamespace LinqToSql\n{\n    [Table(Name=\"Customers\")]\n    public class Customer\n    {\n        [Column]\n        public string customerId {get; set;}\n        [Column]\n        public string companyName {get; set;}\n        [Column]\n        public string city {get; set;}\n        [Column]\n        public string country {get; set;}\n    }\n\n    class LinqToSql\n    {\n        static void Main(string[] args)\n        {\n            string connString = @\"Server=.SQLEXPRESS; \n            Database=Northwind; Trusted_Connection=Yes\";\n            DataContext db = new DataContext(connString);\n            \n            \/\/ crate typed table\n            Table<Customer> customers = db.GetTable<Customer>();            \n            \/\/query database\n            var custs = from c in customers\n                        where c.country ==\"USA\"\n                        select c;\n            \/\/display customers\n            foreach (var cust in custs)\n            {\n                Console.WriteLine(\n                    \"{0} {1} {2} {3}\", \n                    cust.customerId, cust.companyName, cust.city, cust.country\n                    );\n            }\n            db = null;\n        }\n    }\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can crate a Plain Old CLR Object to map the underlining database table w\/o the help of the LINQ-to-SQL designer. To represent a customer class, you need the following code. using System; using System.Collections.Generic; using System.Linq; using System.Data.Linq; using &hellip; <a href=\"http:\/\/kennywu.info\/?p=115\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[40],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry","category-database","category-programing","tag-linq"],"_links":{"self":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=115"}],"version-history":[{"count":0,"href":"http:\/\/kennywu.info\/index.php?rest_route=\/wp\/v2\/posts\/115\/revisions"}],"wp:attachment":[{"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kennywu.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}