[{"data":1,"prerenderedAt":1264},["ShallowReactive",2],{"blog:2009:linq-to-sql-tips-and-tricks-1":3,"blogMore-Development":993,"comments-linq-to-sql-tips-and-tricks-1":1006},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"excerpt":11,"category":26,"tags":27,"body":32,"_type":985,"_id":986,"_source":987,"_file":988,"_stem":989,"_extension":990,"url":991,"wordCount":992,"minutes":139,"commentCount":196},"/blog/2009/linq-to-sql-tips-and-tricks-1","2009",false,"en","LINQ to SQL tips and tricks #1","Being on the inside of a product team often leads to uncovering or stumbling upon lesser-known techniques, and here are a few little nuggets I found interesting. I have more if there is interest.","2009-03-16T14:01:51+00:00",{"type":12,"children":13},"root",[14,21],{"type":15,"tag":16,"props":17,"children":18},"element","p",{},[19],{"type":20,"value":9},"text",{"type":15,"tag":16,"props":22,"children":23},{},[24],{"type":20,"value":25},"LINQ to SQL lets you specify that a property is delay-loaded, meaning that not retrieved as part of normal query operations against that entity. This is particularly useful for binary and large text fields such as a photo property on an employee object that is rarely used and would cause a large amount of memory to be consumed on the client, not to mention traffic between the SQL and application.","Development",[28,29,30,31],".NET","LINQ","SQL","C#",{"type":12,"children":33,"toc":980},[34,38,45,49,54,218,224,229,234,329,334,592,598,603,621,949,965,974],{"type":15,"tag":16,"props":35,"children":36},{},[37],{"type":20,"value":9},{"type":15,"tag":39,"props":40,"children":42},"h2",{"id":41},"loading-a-delay-loaded-property",[43],{"type":20,"value":44},"Loading a delay-loaded property",{"type":15,"tag":16,"props":46,"children":47},{},[48],{"type":20,"value":25},{"type":15,"tag":16,"props":50,"children":51},{},[52],{"type":20,"value":53},"There are times, however, when you want all these binaries returned in a single query, say, for example, returning all the photos for the company photo intranet page:",{"type":15,"tag":55,"props":56,"children":61},"pre",{"className":57,"code":58,"language":59,"meta":60,"style":60},"language-csharp shiki shiki-themes everforest-light dracula","var db = new NorthwindContext();\nvar loadOptions = new DataLoadOptions();\nloadOptions.LoadWith\u003CEmployee>(e => e.Photo);\ndb.LoadOptions = loadOptions;\n","csharp","",[62],{"type":15,"tag":63,"props":64,"children":65},"code",{"__ignoreMap":60},[66,107,137,194],{"type":15,"tag":67,"props":68,"children":71},"span",{"class":69,"line":70},"line",1,[72,78,84,90,96,102],{"type":15,"tag":67,"props":73,"children":75},{"style":74},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[76],{"type":20,"value":77},"var",{"type":15,"tag":67,"props":79,"children":81},{"style":80},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[82],{"type":20,"value":83}," db ",{"type":15,"tag":67,"props":85,"children":87},{"style":86},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[88],{"type":20,"value":89},"=",{"type":15,"tag":67,"props":91,"children":93},{"style":92},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[94],{"type":20,"value":95}," new",{"type":15,"tag":67,"props":97,"children":99},{"style":98},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[100],{"type":20,"value":101}," NorthwindContext",{"type":15,"tag":67,"props":103,"children":104},{"style":80},[105],{"type":20,"value":106},"();\n",{"type":15,"tag":67,"props":108,"children":110},{"class":69,"line":109},2,[111,115,120,124,128,133],{"type":15,"tag":67,"props":112,"children":113},{"style":74},[114],{"type":20,"value":77},{"type":15,"tag":67,"props":116,"children":117},{"style":80},[118],{"type":20,"value":119}," loadOptions ",{"type":15,"tag":67,"props":121,"children":122},{"style":86},[123],{"type":20,"value":89},{"type":15,"tag":67,"props":125,"children":126},{"style":92},[127],{"type":20,"value":95},{"type":15,"tag":67,"props":129,"children":130},{"style":98},[131],{"type":20,"value":132}," DataLoadOptions",{"type":15,"tag":67,"props":134,"children":135},{"style":80},[136],{"type":20,"value":106},{"type":15,"tag":67,"props":138,"children":140},{"class":69,"line":139},3,[141,146,152,157,162,167,173,178,183,189],{"type":15,"tag":67,"props":142,"children":143},{"style":80},[144],{"type":20,"value":145},"loadOptions.",{"type":15,"tag":67,"props":147,"children":149},{"style":148},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[150],{"type":20,"value":151},"LoadWith",{"type":15,"tag":67,"props":153,"children":154},{"style":80},[155],{"type":20,"value":156},"\u003C",{"type":15,"tag":67,"props":158,"children":159},{"style":98},[160],{"type":20,"value":161},"Employee",{"type":15,"tag":67,"props":163,"children":164},{"style":80},[165],{"type":20,"value":166},">(",{"type":15,"tag":67,"props":168,"children":170},{"style":169},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[171],{"type":20,"value":172},"e",{"type":15,"tag":67,"props":174,"children":175},{"style":86},[176],{"type":20,"value":177}," =>",{"type":15,"tag":67,"props":179,"children":180},{"style":80},[181],{"type":20,"value":182}," e.",{"type":15,"tag":67,"props":184,"children":186},{"style":185},"--shiki-default:#35A77C;--shiki-dark:#F8F8F2",[187],{"type":20,"value":188},"Photo",{"type":15,"tag":67,"props":190,"children":191},{"style":80},[192],{"type":20,"value":193},");\n",{"type":15,"tag":67,"props":195,"children":197},{"class":69,"line":196},4,[198,203,208,213],{"type":15,"tag":67,"props":199,"children":200},{"style":80},[201],{"type":20,"value":202},"db.",{"type":15,"tag":67,"props":204,"children":205},{"style":185},[206],{"type":20,"value":207},"LoadOptions",{"type":15,"tag":67,"props":209,"children":210},{"style":86},[211],{"type":20,"value":212}," =",{"type":15,"tag":67,"props":214,"children":215},{"style":80},[216],{"type":20,"value":217}," loadOptions;\n",{"type":15,"tag":39,"props":219,"children":221},{"id":220},"multiple-entity-types-from-a-single-stored-procedure",[222],{"type":20,"value":223},"Multiple entity types from a single stored procedure",{"type":15,"tag":16,"props":225,"children":226},{},[227],{"type":20,"value":228},"It is possible to return multiple entity types from a single stored procedure in LINQ to SQL, although this is not well known as the LINQ to SQL designer doesn’t support it. It is necessary to hand-edit the DBML and then use SQL Metal (or my T4 template) to produce the required method signature.",{"type":15,"tag":16,"props":230,"children":231},{},[232],{"type":20,"value":233},"It is easier to write the code yourself and add it to the non-generated portion of your data context. If you imagine a stored procedure GetStaticData that looks like this:",{"type":15,"tag":55,"props":235,"children":239},{"className":236,"code":237,"language":238,"meta":60,"style":60},"language-sql shiki shiki-themes everforest-light dracula","CREATE PROCEDURE GetStaticData AS\n  SELECT * FROM Region\n  SELECT * FROM Categories\n  SELECT * FROM Territories\n","sql",[240],{"type":15,"tag":63,"props":241,"children":242},{"__ignoreMap":60},[243,266,289,309],{"type":15,"tag":67,"props":244,"children":245},{"class":69,"line":70},[246,251,256,261],{"type":15,"tag":67,"props":247,"children":248},{"style":92},[249],{"type":20,"value":250},"CREATE",{"type":15,"tag":67,"props":252,"children":253},{"style":92},[254],{"type":20,"value":255}," PROCEDURE",{"type":15,"tag":67,"props":257,"children":258},{"style":80},[259],{"type":20,"value":260}," GetStaticData ",{"type":15,"tag":67,"props":262,"children":263},{"style":92},[264],{"type":20,"value":265},"AS\n",{"type":15,"tag":67,"props":267,"children":268},{"class":69,"line":109},[269,274,279,284],{"type":15,"tag":67,"props":270,"children":271},{"style":92},[272],{"type":20,"value":273},"  SELECT",{"type":15,"tag":67,"props":275,"children":276},{"style":86},[277],{"type":20,"value":278}," *",{"type":15,"tag":67,"props":280,"children":281},{"style":92},[282],{"type":20,"value":283}," FROM",{"type":15,"tag":67,"props":285,"children":286},{"style":80},[287],{"type":20,"value":288}," Region\n",{"type":15,"tag":67,"props":290,"children":291},{"class":69,"line":139},[292,296,300,304],{"type":15,"tag":67,"props":293,"children":294},{"style":92},[295],{"type":20,"value":273},{"type":15,"tag":67,"props":297,"children":298},{"style":86},[299],{"type":20,"value":278},{"type":15,"tag":67,"props":301,"children":302},{"style":92},[303],{"type":20,"value":283},{"type":15,"tag":67,"props":305,"children":306},{"style":80},[307],{"type":20,"value":308}," Categories\n",{"type":15,"tag":67,"props":310,"children":311},{"class":69,"line":196},[312,316,320,324],{"type":15,"tag":67,"props":313,"children":314},{"style":92},[315],{"type":20,"value":273},{"type":15,"tag":67,"props":317,"children":318},{"style":86},[319],{"type":20,"value":278},{"type":15,"tag":67,"props":321,"children":322},{"style":92},[323],{"type":20,"value":283},{"type":15,"tag":67,"props":325,"children":326},{"style":80},[327],{"type":20,"value":328}," Territories\n",{"type":15,"tag":16,"props":330,"children":331},{},[332],{"type":20,"value":333},"Then all you need to do is write a method signature that looks like this (the sequence of result type attributes must match the order in the stored procedure):",{"type":15,"tag":55,"props":335,"children":337},{"className":57,"code":336,"language":59,"meta":60,"style":60},"[Function(Name=@\"dbo.DynamicContractsActiveBetween\")]\n[ResultType(typeof(Region))]\n[ResultType(typeof(Category))]\n[ResultType(typeof(Territory))]\npublic IMultipleResults GetStaticData() {\n   return (IMultipleResults) ExecuteMethodCall(this, (MethodInfo) MethodInfo.GetCurrentMethod()).ReturnValue;\n}\n",[338],{"type":15,"tag":63,"props":339,"children":340},{"__ignoreMap":60},[341,385,421,453,485,509,583],{"type":15,"tag":67,"props":342,"children":343},{"class":69,"line":70},[344,349,354,359,363,369,375,380],{"type":15,"tag":67,"props":345,"children":346},{"style":80},[347],{"type":20,"value":348},"[",{"type":15,"tag":67,"props":350,"children":351},{"style":98},[352],{"type":20,"value":353},"Function",{"type":15,"tag":67,"props":355,"children":356},{"style":80},[357],{"type":20,"value":358},"(Name",{"type":15,"tag":67,"props":360,"children":361},{"style":86},[362],{"type":20,"value":89},{"type":15,"tag":67,"props":364,"children":366},{"style":365},"--shiki-default:#8DA101;--shiki-dark:#E9F284",[367],{"type":20,"value":368},"@\"",{"type":15,"tag":67,"props":370,"children":372},{"style":371},"--shiki-default:#8DA101;--shiki-dark:#F1FA8C",[373],{"type":20,"value":374},"dbo.DynamicContractsActiveBetween",{"type":15,"tag":67,"props":376,"children":377},{"style":365},[378],{"type":20,"value":379},"\"",{"type":15,"tag":67,"props":381,"children":382},{"style":80},[383],{"type":20,"value":384},")]\n",{"type":15,"tag":67,"props":386,"children":387},{"class":69,"line":109},[388,392,397,402,407,411,416],{"type":15,"tag":67,"props":389,"children":390},{"style":80},[391],{"type":20,"value":348},{"type":15,"tag":67,"props":393,"children":394},{"style":98},[395],{"type":20,"value":396},"ResultType",{"type":15,"tag":67,"props":398,"children":399},{"style":80},[400],{"type":20,"value":401},"(",{"type":15,"tag":67,"props":403,"children":404},{"style":92},[405],{"type":20,"value":406},"typeof",{"type":15,"tag":67,"props":408,"children":409},{"style":80},[410],{"type":20,"value":401},{"type":15,"tag":67,"props":412,"children":413},{"style":98},[414],{"type":20,"value":415},"Region",{"type":15,"tag":67,"props":417,"children":418},{"style":80},[419],{"type":20,"value":420},"))]\n",{"type":15,"tag":67,"props":422,"children":423},{"class":69,"line":139},[424,428,432,436,440,444,449],{"type":15,"tag":67,"props":425,"children":426},{"style":80},[427],{"type":20,"value":348},{"type":15,"tag":67,"props":429,"children":430},{"style":98},[431],{"type":20,"value":396},{"type":15,"tag":67,"props":433,"children":434},{"style":80},[435],{"type":20,"value":401},{"type":15,"tag":67,"props":437,"children":438},{"style":92},[439],{"type":20,"value":406},{"type":15,"tag":67,"props":441,"children":442},{"style":80},[443],{"type":20,"value":401},{"type":15,"tag":67,"props":445,"children":446},{"style":98},[447],{"type":20,"value":448},"Category",{"type":15,"tag":67,"props":450,"children":451},{"style":80},[452],{"type":20,"value":420},{"type":15,"tag":67,"props":454,"children":455},{"class":69,"line":196},[456,460,464,468,472,476,481],{"type":15,"tag":67,"props":457,"children":458},{"style":80},[459],{"type":20,"value":348},{"type":15,"tag":67,"props":461,"children":462},{"style":98},[463],{"type":20,"value":396},{"type":15,"tag":67,"props":465,"children":466},{"style":80},[467],{"type":20,"value":401},{"type":15,"tag":67,"props":469,"children":470},{"style":92},[471],{"type":20,"value":406},{"type":15,"tag":67,"props":473,"children":474},{"style":80},[475],{"type":20,"value":401},{"type":15,"tag":67,"props":477,"children":478},{"style":98},[479],{"type":20,"value":480},"Territory",{"type":15,"tag":67,"props":482,"children":483},{"style":80},[484],{"type":20,"value":420},{"type":15,"tag":67,"props":486,"children":488},{"class":69,"line":487},5,[489,494,499,504],{"type":15,"tag":67,"props":490,"children":491},{"style":86},[492],{"type":20,"value":493},"public",{"type":15,"tag":67,"props":495,"children":496},{"style":98},[497],{"type":20,"value":498}," IMultipleResults",{"type":15,"tag":67,"props":500,"children":501},{"style":148},[502],{"type":20,"value":503}," GetStaticData",{"type":15,"tag":67,"props":505,"children":506},{"style":80},[507],{"type":20,"value":508},"() {\n",{"type":15,"tag":67,"props":510,"children":512},{"class":69,"line":511},6,[513,518,523,528,533,538,542,548,553,558,563,568,573,578],{"type":15,"tag":67,"props":514,"children":515},{"style":92},[516],{"type":20,"value":517},"   return",{"type":15,"tag":67,"props":519,"children":520},{"style":80},[521],{"type":20,"value":522}," (",{"type":15,"tag":67,"props":524,"children":525},{"style":98},[526],{"type":20,"value":527},"IMultipleResults",{"type":15,"tag":67,"props":529,"children":530},{"style":80},[531],{"type":20,"value":532},") ",{"type":15,"tag":67,"props":534,"children":535},{"style":148},[536],{"type":20,"value":537},"ExecuteMethodCall",{"type":15,"tag":67,"props":539,"children":540},{"style":80},[541],{"type":20,"value":401},{"type":15,"tag":67,"props":543,"children":545},{"style":544},"--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#BD93F9;--shiki-dark-font-style:italic",[546],{"type":20,"value":547},"this",{"type":15,"tag":67,"props":549,"children":550},{"style":80},[551],{"type":20,"value":552},", (",{"type":15,"tag":67,"props":554,"children":555},{"style":98},[556],{"type":20,"value":557},"MethodInfo",{"type":15,"tag":67,"props":559,"children":560},{"style":80},[561],{"type":20,"value":562},") MethodInfo.",{"type":15,"tag":67,"props":564,"children":565},{"style":148},[566],{"type":20,"value":567},"GetCurrentMethod",{"type":15,"tag":67,"props":569,"children":570},{"style":80},[571],{"type":20,"value":572},"()).",{"type":15,"tag":67,"props":574,"children":575},{"style":185},[576],{"type":20,"value":577},"ReturnValue",{"type":15,"tag":67,"props":579,"children":580},{"style":80},[581],{"type":20,"value":582},";\n",{"type":15,"tag":67,"props":584,"children":586},{"class":69,"line":585},7,[587],{"type":15,"tag":67,"props":588,"children":589},{"style":80},[590],{"type":20,"value":591},"}\n",{"type":15,"tag":39,"props":593,"children":595},{"id":594},"intercepting-create-update-and-delete-operations",[596],{"type":20,"value":597},"Intercepting create, update and delete operations",{"type":15,"tag":16,"props":599,"children":600},{},[601],{"type":20,"value":602},"There are times when it is useful to listen to events and perform your own logic, perhaps auditing or logging for some scenarios. The easiest way is to implement some specially-named methods on your data context, perform your action, then dispatch the call back to LINQ to SQL.",{"type":15,"tag":16,"props":604,"children":605},{},[606,608,613,615,619],{"type":20,"value":607},"The format of these specially-named methods is [Action][Entity], and you should pass back control to LINQ to SQL using ExecuteDynamic",{"type":15,"tag":67,"props":609,"children":610},{},[611],{"type":20,"value":612},"Action",{"type":20,"value":614}," where ",{"type":15,"tag":67,"props":616,"children":617},{},[618],{"type":20,"value":612},{"type":20,"value":620}," is either Insert, Update or Delete. One example of such usage might be:",{"type":15,"tag":55,"props":622,"children":624},{"className":57,"code":623,"language":59,"meta":60,"style":60},"partial class NorthwindContext {\n   partial void InsertEmployee(Employee instance) {\n      instance.CreatedBy = CurrentUser;\n      instance.CreatedAt = DateTime.Now;\n      ExecuteDynamicInsert(instance);\n   }\n\n   partial void UpdateEmployee(Employee instance) {\n      AuditEmployeeOwnerChange(instance);\n      instance.LastModifiedAt = DateTime.Now;\n      ExecuteDynamicUpdate(instance);\n   }\n\n   partial void DeleteEmployee(Employee instance) {\n      AuditDelete(instance, CurrentUser);\n      ExecuteDynamicDelete(instance);\n   }\n}\n",[625],{"type":15,"tag":63,"props":626,"children":627},{"__ignoreMap":60},[628,651,687,709,739,752,760,769,802,815,844,857,865,873,906,920,933,941],{"type":15,"tag":67,"props":629,"children":630},{"class":69,"line":70},[631,636,641,646],{"type":15,"tag":67,"props":632,"children":633},{"style":86},[634],{"type":20,"value":635},"partial",{"type":15,"tag":67,"props":637,"children":638},{"style":92},[639],{"type":20,"value":640}," class",{"type":15,"tag":67,"props":642,"children":644},{"style":643},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[645],{"type":20,"value":101},{"type":15,"tag":67,"props":647,"children":648},{"style":80},[649],{"type":20,"value":650}," {\n",{"type":15,"tag":67,"props":652,"children":653},{"class":69,"line":109},[654,659,664,669,673,677,682],{"type":15,"tag":67,"props":655,"children":656},{"style":86},[657],{"type":20,"value":658},"   partial",{"type":15,"tag":67,"props":660,"children":661},{"style":74},[662],{"type":20,"value":663}," void",{"type":15,"tag":67,"props":665,"children":666},{"style":148},[667],{"type":20,"value":668}," InsertEmployee",{"type":15,"tag":67,"props":670,"children":671},{"style":80},[672],{"type":20,"value":401},{"type":15,"tag":67,"props":674,"children":675},{"style":98},[676],{"type":20,"value":161},{"type":15,"tag":67,"props":678,"children":679},{"style":169},[680],{"type":20,"value":681}," instance",{"type":15,"tag":67,"props":683,"children":684},{"style":80},[685],{"type":20,"value":686},") {\n",{"type":15,"tag":67,"props":688,"children":689},{"class":69,"line":139},[690,695,700,704],{"type":15,"tag":67,"props":691,"children":692},{"style":80},[693],{"type":20,"value":694},"      instance.",{"type":15,"tag":67,"props":696,"children":697},{"style":185},[698],{"type":20,"value":699},"CreatedBy",{"type":15,"tag":67,"props":701,"children":702},{"style":86},[703],{"type":20,"value":212},{"type":15,"tag":67,"props":705,"children":706},{"style":80},[707],{"type":20,"value":708}," CurrentUser;\n",{"type":15,"tag":67,"props":710,"children":711},{"class":69,"line":196},[712,716,721,725,730,735],{"type":15,"tag":67,"props":713,"children":714},{"style":80},[715],{"type":20,"value":694},{"type":15,"tag":67,"props":717,"children":718},{"style":185},[719],{"type":20,"value":720},"CreatedAt",{"type":15,"tag":67,"props":722,"children":723},{"style":86},[724],{"type":20,"value":212},{"type":15,"tag":67,"props":726,"children":727},{"style":80},[728],{"type":20,"value":729}," DateTime.",{"type":15,"tag":67,"props":731,"children":732},{"style":185},[733],{"type":20,"value":734},"Now",{"type":15,"tag":67,"props":736,"children":737},{"style":80},[738],{"type":20,"value":582},{"type":15,"tag":67,"props":740,"children":741},{"class":69,"line":487},[742,747],{"type":15,"tag":67,"props":743,"children":744},{"style":148},[745],{"type":20,"value":746},"      ExecuteDynamicInsert",{"type":15,"tag":67,"props":748,"children":749},{"style":80},[750],{"type":20,"value":751},"(instance);\n",{"type":15,"tag":67,"props":753,"children":754},{"class":69,"line":511},[755],{"type":15,"tag":67,"props":756,"children":757},{"style":80},[758],{"type":20,"value":759},"   }\n",{"type":15,"tag":67,"props":761,"children":762},{"class":69,"line":585},[763],{"type":15,"tag":67,"props":764,"children":766},{"emptyLinePlaceholder":765},true,[767],{"type":20,"value":768},"\n",{"type":15,"tag":67,"props":770,"children":772},{"class":69,"line":771},8,[773,777,781,786,790,794,798],{"type":15,"tag":67,"props":774,"children":775},{"style":86},[776],{"type":20,"value":658},{"type":15,"tag":67,"props":778,"children":779},{"style":74},[780],{"type":20,"value":663},{"type":15,"tag":67,"props":782,"children":783},{"style":148},[784],{"type":20,"value":785}," UpdateEmployee",{"type":15,"tag":67,"props":787,"children":788},{"style":80},[789],{"type":20,"value":401},{"type":15,"tag":67,"props":791,"children":792},{"style":98},[793],{"type":20,"value":161},{"type":15,"tag":67,"props":795,"children":796},{"style":169},[797],{"type":20,"value":681},{"type":15,"tag":67,"props":799,"children":800},{"style":80},[801],{"type":20,"value":686},{"type":15,"tag":67,"props":803,"children":805},{"class":69,"line":804},9,[806,811],{"type":15,"tag":67,"props":807,"children":808},{"style":148},[809],{"type":20,"value":810},"      AuditEmployeeOwnerChange",{"type":15,"tag":67,"props":812,"children":813},{"style":80},[814],{"type":20,"value":751},{"type":15,"tag":67,"props":816,"children":818},{"class":69,"line":817},10,[819,823,828,832,836,840],{"type":15,"tag":67,"props":820,"children":821},{"style":80},[822],{"type":20,"value":694},{"type":15,"tag":67,"props":824,"children":825},{"style":185},[826],{"type":20,"value":827},"LastModifiedAt",{"type":15,"tag":67,"props":829,"children":830},{"style":86},[831],{"type":20,"value":212},{"type":15,"tag":67,"props":833,"children":834},{"style":80},[835],{"type":20,"value":729},{"type":15,"tag":67,"props":837,"children":838},{"style":185},[839],{"type":20,"value":734},{"type":15,"tag":67,"props":841,"children":842},{"style":80},[843],{"type":20,"value":582},{"type":15,"tag":67,"props":845,"children":847},{"class":69,"line":846},11,[848,853],{"type":15,"tag":67,"props":849,"children":850},{"style":148},[851],{"type":20,"value":852},"      ExecuteDynamicUpdate",{"type":15,"tag":67,"props":854,"children":855},{"style":80},[856],{"type":20,"value":751},{"type":15,"tag":67,"props":858,"children":860},{"class":69,"line":859},12,[861],{"type":15,"tag":67,"props":862,"children":863},{"style":80},[864],{"type":20,"value":759},{"type":15,"tag":67,"props":866,"children":868},{"class":69,"line":867},13,[869],{"type":15,"tag":67,"props":870,"children":871},{"emptyLinePlaceholder":765},[872],{"type":20,"value":768},{"type":15,"tag":67,"props":874,"children":876},{"class":69,"line":875},14,[877,881,885,890,894,898,902],{"type":15,"tag":67,"props":878,"children":879},{"style":86},[880],{"type":20,"value":658},{"type":15,"tag":67,"props":882,"children":883},{"style":74},[884],{"type":20,"value":663},{"type":15,"tag":67,"props":886,"children":887},{"style":148},[888],{"type":20,"value":889}," DeleteEmployee",{"type":15,"tag":67,"props":891,"children":892},{"style":80},[893],{"type":20,"value":401},{"type":15,"tag":67,"props":895,"children":896},{"style":98},[897],{"type":20,"value":161},{"type":15,"tag":67,"props":899,"children":900},{"style":169},[901],{"type":20,"value":681},{"type":15,"tag":67,"props":903,"children":904},{"style":80},[905],{"type":20,"value":686},{"type":15,"tag":67,"props":907,"children":909},{"class":69,"line":908},15,[910,915],{"type":15,"tag":67,"props":911,"children":912},{"style":148},[913],{"type":20,"value":914},"      AuditDelete",{"type":15,"tag":67,"props":916,"children":917},{"style":80},[918],{"type":20,"value":919},"(instance, CurrentUser);\n",{"type":15,"tag":67,"props":921,"children":923},{"class":69,"line":922},16,[924,929],{"type":15,"tag":67,"props":925,"children":926},{"style":148},[927],{"type":20,"value":928},"      ExecuteDynamicDelete",{"type":15,"tag":67,"props":930,"children":931},{"style":80},[932],{"type":20,"value":751},{"type":15,"tag":67,"props":934,"children":936},{"class":69,"line":935},17,[937],{"type":15,"tag":67,"props":938,"children":939},{"style":80},[940],{"type":20,"value":759},{"type":15,"tag":67,"props":942,"children":944},{"class":69,"line":943},18,[945],{"type":15,"tag":67,"props":946,"children":947},{"style":80},[948],{"type":20,"value":591},{"type":15,"tag":950,"props":951,"children":952},"blockquote",{},[953],{"type":15,"tag":16,"props":954,"children":955},{},[956,958],{"type":20,"value":957},"Check out ",{"type":15,"tag":959,"props":960,"children":962},"a",{"href":961},"/blog/2009/linq-to-sql-tips-and-tricks-2/",[963],{"type":20,"value":964},"part 2 of LINQ to SQL tips",{"type":15,"tag":16,"props":966,"children":967},{},[968],{"type":15,"tag":969,"props":970,"children":971},"em",{},[972],{"type":20,"value":973},"[)amien",{"type":15,"tag":975,"props":976,"children":977},"style",{},[978],{"type":20,"value":979},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":60,"searchDepth":109,"depth":109,"links":981},[982,983,984],{"id":41,"depth":109,"text":44},{"id":220,"depth":109,"text":223},{"id":594,"depth":109,"text":597},"markdown","content:blog:2009:linq-to-sql-tips-and-tricks-1.md","content","blog/2009/linq-to-sql-tips-and-tricks-1.md","blog/2009/linq-to-sql-tips-and-tricks-1","md","/blog/2009/linq-to-sql-tips-and-tricks-1/",546,[994,998,1002],{"title":995,"date":996,"url":997},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":999,"date":1000,"url":1001},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":1003,"date":1004,"url":1005},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[1007,1028,1222,1239],{"_path":1008,"_dir":1009,"_draft":6,"_partial":6,"_locale":7,"title":1010,"description":1011,"id":1012,"name":1013,"email":1014,"avatar":1015,"date":1016,"body":1017,"_type":985,"_id":1025,"_source":987,"_file":1026,"_stem":1027,"_extension":990},"/comments/linq-to-sql-tips-and-tricks-1/17723","linq-to-sql-tips-and-tricks-1","17723","@Zhaph Thanks, sometimes it is hard to ask the question when you don't have the words for it. I appreciate the tip!",17723,"Michael D. Hall","mhall@just3ws.com","https://www.gravatar.com/avatar/7ff506d8ec192501ed9730d7a9b040f7?r=pg&d=retro","2009-05-20T19:39:39",{"type":12,"children":1018,"toc":1023},[1019],{"type":15,"tag":16,"props":1020,"children":1021},{},[1022],{"type":20,"value":1011},{"title":60,"searchDepth":109,"depth":109,"links":1024},[],"content:comments:linq-to-sql-tips-and-tricks-1:17723.md","comments/linq-to-sql-tips-and-tricks-1/17723.md","comments/linq-to-sql-tips-and-tricks-1/17723",{"_path":1029,"_dir":1009,"_draft":6,"_partial":6,"_locale":7,"title":1030,"description":1031,"id":1032,"name":1033,"email":1034,"avatar":1035,"url":1036,"date":1037,"body":1038,"_type":985,"_id":1219,"_source":987,"_file":1220,"_stem":1221,"_extension":990},"/comments/linq-to-sql-tips-and-tricks-1/17673","17673","@Michael - searching for \"Linq to SQL Extensibility\" is a good start - that's the name given to those methods in the default generated code:",17673,"Zhaph - Ben Duguid","ben@doodle.co.uk","https://www.gravatar.com/avatar/ef3e872b7359633a74dc57bd708fde22?r=pg&d=retro","https://www.doodle.co.uk/Blogs/","2009-05-20T07:48:12",{"type":12,"children":1039,"toc":1217},[1040,1044,1201,1213],{"type":15,"tag":16,"props":1041,"children":1042},{},[1043],{"type":20,"value":1031},{"type":15,"tag":55,"props":1045,"children":1047},{"className":57,"code":1046,"language":59,"meta":60,"style":60},"#region Extensibility Method Definitions\npartial void OnCreated();\npartial void InsertsiteContent_Album(siteContent_Album instance);\npartial void UpdatesiteContent_Album(siteContent_Album instance);\npartial void DeletesiteContent_Album(siteContent_Album instance);\n#endregion\n",[1048],{"type":15,"tag":63,"props":1049,"children":1050},{"__ignoreMap":60},[1051,1072,1092,1125,1157,1189],{"type":15,"tag":67,"props":1052,"children":1053},{"class":69,"line":70},[1054,1060,1066],{"type":15,"tag":67,"props":1055,"children":1057},{"style":1056},"--shiki-default:#5C6A72;--shiki-dark:#FF79C6",[1058],{"type":20,"value":1059},"#",{"type":15,"tag":67,"props":1061,"children":1063},{"style":1062},"--shiki-default:#35A77C;--shiki-dark:#FF79C6",[1064],{"type":20,"value":1065},"region",{"type":15,"tag":67,"props":1067,"children":1069},{"style":1068},"--shiki-default:#DFA000;--shiki-dark:#F1FA8C",[1070],{"type":20,"value":1071}," Extensibility Method Definitions\n",{"type":15,"tag":67,"props":1073,"children":1074},{"class":69,"line":109},[1075,1079,1083,1088],{"type":15,"tag":67,"props":1076,"children":1077},{"style":86},[1078],{"type":20,"value":635},{"type":15,"tag":67,"props":1080,"children":1081},{"style":74},[1082],{"type":20,"value":663},{"type":15,"tag":67,"props":1084,"children":1085},{"style":148},[1086],{"type":20,"value":1087}," OnCreated",{"type":15,"tag":67,"props":1089,"children":1090},{"style":80},[1091],{"type":20,"value":106},{"type":15,"tag":67,"props":1093,"children":1094},{"class":69,"line":139},[1095,1099,1103,1108,1112,1117,1121],{"type":15,"tag":67,"props":1096,"children":1097},{"style":86},[1098],{"type":20,"value":635},{"type":15,"tag":67,"props":1100,"children":1101},{"style":74},[1102],{"type":20,"value":663},{"type":15,"tag":67,"props":1104,"children":1105},{"style":148},[1106],{"type":20,"value":1107}," InsertsiteContent_Album",{"type":15,"tag":67,"props":1109,"children":1110},{"style":80},[1111],{"type":20,"value":401},{"type":15,"tag":67,"props":1113,"children":1114},{"style":98},[1115],{"type":20,"value":1116},"siteContent_Album",{"type":15,"tag":67,"props":1118,"children":1119},{"style":169},[1120],{"type":20,"value":681},{"type":15,"tag":67,"props":1122,"children":1123},{"style":80},[1124],{"type":20,"value":193},{"type":15,"tag":67,"props":1126,"children":1127},{"class":69,"line":196},[1128,1132,1136,1141,1145,1149,1153],{"type":15,"tag":67,"props":1129,"children":1130},{"style":86},[1131],{"type":20,"value":635},{"type":15,"tag":67,"props":1133,"children":1134},{"style":74},[1135],{"type":20,"value":663},{"type":15,"tag":67,"props":1137,"children":1138},{"style":148},[1139],{"type":20,"value":1140}," UpdatesiteContent_Album",{"type":15,"tag":67,"props":1142,"children":1143},{"style":80},[1144],{"type":20,"value":401},{"type":15,"tag":67,"props":1146,"children":1147},{"style":98},[1148],{"type":20,"value":1116},{"type":15,"tag":67,"props":1150,"children":1151},{"style":169},[1152],{"type":20,"value":681},{"type":15,"tag":67,"props":1154,"children":1155},{"style":80},[1156],{"type":20,"value":193},{"type":15,"tag":67,"props":1158,"children":1159},{"class":69,"line":487},[1160,1164,1168,1173,1177,1181,1185],{"type":15,"tag":67,"props":1161,"children":1162},{"style":86},[1163],{"type":20,"value":635},{"type":15,"tag":67,"props":1165,"children":1166},{"style":74},[1167],{"type":20,"value":663},{"type":15,"tag":67,"props":1169,"children":1170},{"style":148},[1171],{"type":20,"value":1172}," DeletesiteContent_Album",{"type":15,"tag":67,"props":1174,"children":1175},{"style":80},[1176],{"type":20,"value":401},{"type":15,"tag":67,"props":1178,"children":1179},{"style":98},[1180],{"type":20,"value":1116},{"type":15,"tag":67,"props":1182,"children":1183},{"style":169},[1184],{"type":20,"value":681},{"type":15,"tag":67,"props":1186,"children":1187},{"style":80},[1188],{"type":20,"value":193},{"type":15,"tag":67,"props":1190,"children":1191},{"class":69,"line":511},[1192,1196],{"type":15,"tag":67,"props":1193,"children":1194},{"style":1056},[1195],{"type":20,"value":1059},{"type":15,"tag":67,"props":1197,"children":1198},{"style":1062},[1199],{"type":20,"value":1200},"endregion\n",{"type":15,"tag":16,"props":1202,"children":1203},{},[1204,1206],{"type":20,"value":1205},"Alternatively, ScottGu calls them \"Custom Entity Insert/Update/Delete Method Validation\" in his post: ",{"type":15,"tag":959,"props":1207,"children":1211},{"href":1208,"rel":1209},"http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx",[1210],"nofollow",[1212],{"type":20,"value":1208},{"type":15,"tag":975,"props":1214,"children":1215},{},[1216],{"type":20,"value":979},{"title":60,"searchDepth":109,"depth":109,"links":1218},[],"content:comments:linq-to-sql-tips-and-tricks-1:17673.md","comments/linq-to-sql-tips-and-tricks-1/17673.md","comments/linq-to-sql-tips-and-tricks-1/17673",{"_path":1223,"_dir":1009,"_draft":6,"_partial":6,"_locale":7,"title":1224,"description":1225,"id":1226,"name":1013,"email":1014,"avatar":1015,"date":1227,"body":1228,"_type":985,"_id":1236,"_source":987,"_file":1237,"_stem":1238,"_extension":990},"/comments/linq-to-sql-tips-and-tricks-1/17544","17544","The interception feature is awesome, I can't believe that one flew under the radar. I'm not sure how to query for that in Google though, as there are allot of people who've rolled their own auditing functionality for L2S, can you point to some documentation or give a more complete example. I would appreciate that very much, thanks.",17544,"2009-05-18T22:14:14",{"type":12,"children":1229,"toc":1234},[1230],{"type":15,"tag":16,"props":1231,"children":1232},{},[1233],{"type":20,"value":1225},{"title":60,"searchDepth":109,"depth":109,"links":1235},[],"content:comments:linq-to-sql-tips-and-tricks-1:17544.md","comments/linq-to-sql-tips-and-tricks-1/17544.md","comments/linq-to-sql-tips-and-tricks-1/17544",{"_path":1240,"_dir":1009,"_draft":6,"_partial":6,"_locale":7,"title":1241,"description":1242,"id":1243,"name":1244,"email":1245,"avatar":1246,"date":1247,"body":1248,"_type":985,"_id":1261,"_source":987,"_file":1262,"_stem":1263,"_extension":990},"/comments/linq-to-sql-tips-and-tricks-1/12180","12180","Cool. Keep the tricks coming.",12180,"Ibleif","ibleif@hotmail.com","https://www.gravatar.com/avatar/795a09601be3765833ddf7d630615357?r=pg&d=retro","2009-03-18T13:00:19",{"type":12,"children":1249,"toc":1259},[1250,1254],{"type":15,"tag":16,"props":1251,"children":1252},{},[1253],{"type":20,"value":1242},{"type":15,"tag":16,"props":1255,"children":1256},{},[1257],{"type":20,"value":1258},"Would also be cool if you could reveal some of the upcoming features/changes to \"LINQ to SQL\" ?",{"title":60,"searchDepth":109,"depth":109,"links":1260},[],"content:comments:linq-to-sql-tips-and-tricks-1:12180.md","comments/linq-to-sql-tips-and-tricks-1/12180.md","comments/linq-to-sql-tips-and-tricks-1/12180",1779264585769]