[{"data":1,"prerenderedAt":381},["ShallowReactive",2],{"blog:2008:experimental-linq-to-sql-template-for-t4":3,"blogMore-Development":270,"comments-experimental-linq-to-sql-template-for-t4":283},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":18,"body":38,"_type":262,"_id":263,"_source":264,"_file":265,"_stem":266,"_extension":267,"url":268,"wordCount":269,"minutes":258,"commentCount":261},"/blog/2008/experimental-linq-to-sql-template-for-t4","2008",false,"en","Experimental LINQ to SQL template","","2008-06-25T22:12:46+00:00","Development",[13,14,15,16,17],".NET","C#","LINQ","T4","Visual Studio",{"type":19,"children":20},"root",[21,33],{"type":22,"tag":23,"props":24,"children":25},"element","p",{},[26,29,31],{"type":27,"value":28},"text","A ",{"type":27,"value":30},"newer version of this LINQ to SQL template",{"type":27,"value":32}," is available",{"type":22,"tag":23,"props":34,"children":35},{},[36],{"type":27,"value":37},"While SQLMetal does a good job of turning your SQL schema into a set of classes for you it doesn’t let you customize the code generation process.",{"type":19,"children":39,"toc":257},[40,55,59,74,79,93,106,111,161,168,249],{"type":22,"tag":41,"props":42,"children":43},"blockquote",{},[44],{"type":22,"tag":23,"props":45,"children":46},{},[47,48,54],{"type":27,"value":28},{"type":22,"tag":49,"props":50,"children":52},"a",{"href":51},"/blog/2009/linq-to-sql-templates-updated-now-on-codeplex/",[53],{"type":27,"value":30},{"type":27,"value":32},{"type":22,"tag":23,"props":56,"children":57},{},[58],{"type":27,"value":37},{"type":22,"tag":23,"props":60,"children":61},{},[62,64,72],{"type":27,"value":63},"Usefully there is now a templating system built into Visual Studio 2008 called ",{"type":22,"tag":49,"props":65,"children":69},{"href":66,"rel":67},"https://msdn.microsoft.com/en-us/library/bb126445.aspx",[68],"nofollow",[70],{"type":27,"value":71},"Text Templates",{"type":27,"value":73}," (T4 for short).",{"type":22,"tag":23,"props":75,"children":76},{},[77],{"type":27,"value":78},"Here is a short (369 line) experimental proof-of-concept T4 template I wrote last night that will generate a data context and associated entity classes as a starting point similar to that produced by SQLMetal.",{"type":22,"tag":23,"props":80,"children":81},{},[82,84,91],{"type":27,"value":83},"Once downloaded unzip and drop the DataContext.cs.tt into your project and edit line 17 to set the connection string. You can also edit lines 18 and 19 to set the namespace and class name. The lightweight wrappers around database, table and column can be found at the end of the file; they simply wrap the SQL Server ",{"type":22,"tag":85,"props":86,"children":88},"code",{"className":87},[],[89],{"type":27,"value":90},"Information_Schema",{"type":27,"value":92}," views as briefly as possible.",{"type":22,"tag":23,"props":94,"children":95},{},[96,98,104],{"type":27,"value":97},"Within seconds Visual Studio should have created a code-behind file for the ",{"type":22,"tag":85,"props":99,"children":101},{"className":100},[],[102],{"type":27,"value":103},"DataContext",{"type":27,"value":105}," named DataContext.cs.cs with your generated code ready to use :) If you don’t like the way the template generates your context you can change it :)",{"type":22,"tag":23,"props":107,"children":108},{},[109],{"type":27,"value":110},"There are limitations with this experimental proof-of-concept including: ",{"type":22,"tag":112,"props":113,"children":114},"ul",{},[115,117,123,124,129,130,135,136,149,150,155,156],{"type":27,"value":116},"\n  ",{"type":22,"tag":118,"props":119,"children":120},"li",{},[121],{"type":27,"value":122},"\n    Processes all and only tables in the database (no views or SP’s)\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":125,"children":126},{},[127],{"type":27,"value":128},"\n    Foreign-key relationships are not implemented\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":131,"children":132},{},[133],{"type":27,"value":134},"\n    Column attributes for `IsDbGenerated`, `UpdateCheck` and `AutoSync` not implemented\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":137,"children":138},{},[139,141,147],{"type":27,"value":140},"\n    C# only (",{"type":22,"tag":49,"props":142,"children":144},{"href":143},"https://www.thedatafarm.com/blog/",[145],{"type":27,"value":146},"sorry Julie",{"type":27,"value":148},")\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":151,"children":152},{},[153],{"type":27,"value":154},"\n    Plural and singular naming rules are incomplete\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":157,"children":158},{},[159],{"type":27,"value":160},"\n    Can’t modify schema as you could with a designer stage\n  ",{"type":22,"tag":162,"props":163,"children":165},"h3",{"id":164},"learn-more-about-t4",[166],{"type":27,"value":167},"Learn more about T4!",{"type":22,"tag":112,"props":169,"children":170},{},[171,172,185,186,215,216,236,237],{"type":27,"value":116},{"type":22,"tag":118,"props":173,"children":174},{},[175,177,183],{"type":27,"value":176},"\n    Watch a ",{"type":22,"tag":49,"props":178,"children":180},{"href":179},"https://msdn.microsoft.com/en-us/vstudio/cc308634.aspx",[181],{"type":27,"value":182},"screen-cast about T4 in action",{"type":27,"value":184}," (download, embedded player is awful)\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":187,"children":188},{},[189,191,197,199,205,207,213],{"type":27,"value":190},"\n    Grab ",{"type":22,"tag":49,"props":192,"children":194},{"href":193},"https://www.t4editor.net/",[195],{"type":27,"value":196},"T4 Editor",{"type":27,"value":198}," for IntelliSense within T4 and ",{"type":22,"tag":49,"props":200,"children":202},{"href":201},"https://dotnet.org.za/hiltong/archive/2008/02/18/t4-template-items.aspx",[203],{"type":27,"value":204},"T4 Template Items",{"type":27,"value":206}," for ",{"type":22,"tag":208,"props":209,"children":210},"em",{},[211],{"type":27,"value":212},"Add New Item…",{"type":27,"value":214}," support\n  ",{"type":27,"value":116},{"type":22,"tag":118,"props":217,"children":218},{},[219,221,227,229,235],{"type":27,"value":220},"\n    Check out ",{"type":22,"tag":49,"props":222,"children":224},{"href":223},"https://www.olegsych.com/",[225],{"type":27,"value":226},"Oleg Sych’s blog",{"type":27,"value":228}," for great T4 articles including how to ",{"type":22,"tag":49,"props":230,"children":232},{"href":231},"https://www.olegsych.com/2008/02/t4-template-directive/",[233],{"type":27,"value":234},"enable the 3.5 compiler for templates",{"type":27,"value":116},{"type":27,"value":116},{"type":22,"tag":118,"props":238,"children":239},{},[240,242,248],{"type":27,"value":241},"\n    Learn about ",{"type":22,"tag":49,"props":243,"children":245},{"href":244},"https://blogs.msdn.com/garethj/archive/2006/01/09/t4debugging.aspx",[246],{"type":27,"value":247},"T4 debugging",{"type":27,"value":116},{"type":22,"tag":23,"props":250,"children":251},{},[252],{"type":22,"tag":208,"props":253,"children":254},{},[255],{"type":27,"value":256},"[)amien",{"title":9,"searchDepth":258,"depth":258,"links":259},2,[260],{"id":164,"depth":261,"text":167},3,"markdown","content:blog:2008:experimental-linq-to-sql-template-for-t4.md","content","blog/2008/experimental-linq-to-sql-template-for-t4.md","blog/2008/experimental-linq-to-sql-template-for-t4","md","/blog/2008/experimental-linq-to-sql-template-for-t4/",316,[271,275,279],{"title":272,"date":273,"url":274},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":276,"date":277,"url":278},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":280,"date":281,"url":282},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[284,325,351],{"_path":285,"_dir":286,"_draft":6,"_partial":6,"_locale":7,"title":287,"description":288,"id":289,"name":290,"email":291,"avatar":292,"url":293,"date":294,"body":295,"_type":262,"_id":322,"_source":264,"_file":323,"_stem":324,"_extension":267},"/comments/experimental-linq-to-sql-template-for-t4/9576","experimental-linq-to-sql-template-for-t4","9576","@ Damien:",9576,"Victor Garcia Aprea","vga@clariusconsulting.net","https://www.gravatar.com/avatar/8af1993c33b85f5f059e786628811951?r=pg&d=retro","https://weblogs.asp.net/vga","2008-10-05T02:21:48",{"type":19,"children":296,"toc":320},[297,301,315],{"type":22,"tag":23,"props":298,"children":299},{},[300],{"type":27,"value":288},{"type":22,"tag":302,"props":303,"children":304},"ol",{},[305,310],{"type":22,"tag":118,"props":306,"children":307},{},[308],{"type":27,"value":309},"very nice template!",{"type":22,"tag":118,"props":311,"children":312},{},[313],{"type":27,"value":314},"\"...You can't call the T4 template from your own application as T4 is part of the Visual Studio IDE...\" --> actually you CAN use the T4 engine from your own apps, note the T4 engine is not tied to VS at all.",{"type":22,"tag":23,"props":316,"children":317},{},[318],{"type":27,"value":319},"-vga.",{"title":9,"searchDepth":258,"depth":258,"links":321},[],"content:comments:experimental-linq-to-sql-template-for-t4:9576.md","comments/experimental-linq-to-sql-template-for-t4/9576.md","comments/experimental-linq-to-sql-template-for-t4/9576",{"_path":326,"_dir":286,"_draft":6,"_partial":6,"_locale":7,"title":327,"description":328,"id":329,"name":330,"email":331,"avatar":332,"url":333,"date":334,"body":335,"_type":262,"_id":348,"_source":264,"_file":349,"_stem":350,"_extension":267},"/comments/experimental-linq-to-sql-template-for-t4/9042","9042","You can't call the T4 template from your own application as T4 is part of the Visual Studio IDE.",9042,"Damien Guard","damien@envytech.co.uk","https://www.gravatar.com/avatar/dc72963e7279d34c85ed4c0b731ce5a9?r=pg&d=retro","https://damieng.com/","2008-07-19T23:04:20",{"type":19,"children":336,"toc":346},[337,341],{"type":22,"tag":23,"props":338,"children":339},{},[340],{"type":27,"value":328},{"type":22,"tag":23,"props":342,"children":343},{},[344],{"type":27,"value":345},"You can however use the CodeDOM API, CSharpCodeProvider classes and Assembly.Load built into the .NET Framework to develop you own code-building, compilation and execution mechanism from your own applications.",{"title":9,"searchDepth":258,"depth":258,"links":347},[],"content:comments:experimental-linq-to-sql-template-for-t4:9042.md","comments/experimental-linq-to-sql-template-for-t4/9042.md","comments/experimental-linq-to-sql-template-for-t4/9042",{"_path":352,"_dir":286,"_draft":6,"_partial":6,"_locale":7,"title":353,"description":354,"id":355,"name":356,"email":357,"avatar":358,"date":359,"body":360,"_type":262,"_id":378,"_source":264,"_file":379,"_stem":380,"_extension":267},"/comments/experimental-linq-to-sql-template-for-t4/9040","9040","Hi,\nWhat you have done is fantastic.I am getting to grip with the T4 concept and how to write those templates.",9040,"gabriel","gb@devnet247.com","https://www.gravatar.com/avatar/40e146de0aae4e8b79a99b8ef657fb82?r=pg&d=retro","2008-07-19T17:31:31",{"type":19,"children":361,"toc":376},[362,366,371],{"type":22,"tag":23,"props":363,"children":364},{},[365],{"type":27,"value":354},{"type":22,"tag":23,"props":367,"children":368},{},[369],{"type":27,"value":370},"Is it possible to have a form and button and call the template from a windows form?\nAny examples anywhere?",{"type":22,"tag":23,"props":372,"children":373},{},[374],{"type":27,"value":375},"thanks again for sharing this.",{"title":9,"searchDepth":258,"depth":258,"links":377},[],"content:comments:experimental-linq-to-sql-template-for-t4:9040.md","comments/experimental-linq-to-sql-template-for-t4/9040.md","comments/experimental-linq-to-sql-template-for-t4/9040",1779264587158]