<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Linq</title><link>http://blog.steeleprice.net/category/52.aspx</link><description>Linq specific Posts</description><managingEditor>H. Steele Price, IV</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>H. Steele Price, IV</dc:creator><title>Thinking Different with Linq and Lambdas</title><link>http://blog.steeleprice.net/archive/2008/06/03/1503.aspx</link><pubDate>Tue, 03 Jun 2008 17:06:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/06/03/1503.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1503.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/06/03/1503.aspx#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1503.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1503.aspx</trackback:ping><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;Today I had to look through a set of controls to extract the Text and build a dynamic search.&lt;/p&gt; &lt;p&gt;Normally, this means looping and/or a bunch of Ifs to do some validation.&amp;nbsp; With Linq to Objects at our disposal I distilled exactly what I needed down to this:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; q = From c &lt;span class="kwrd"&gt;In&lt;/span&gt; SearchCriteria.Controls _
        Where &lt;span class="kwrd"&gt;TypeOf&lt;/span&gt; c &lt;span class="kwrd"&gt;Is&lt;/span&gt; RadTextBox _
        &lt;span class="kwrd"&gt;AndAlso&lt;/span&gt; c.Text.Length &amp;gt; 0

&lt;span class="kwrd"&gt;Dim&lt;/span&gt; params = q.ToDictionary(Of &lt;span class="kwrd"&gt;String&lt;/span&gt;, &lt;span class="kwrd"&gt;String&lt;/span&gt;)( _
                &lt;span class="kwrd"&gt;Function&lt;/span&gt;(r &lt;span class="kwrd"&gt;As&lt;/span&gt; RadTextBox) r.ID.Remove(0, 5), _
                &lt;span class="kwrd"&gt;Function&lt;/span&gt;(r &lt;span class="kwrd"&gt;As&lt;/span&gt; RadTextBox) r.Text.Trim)
&lt;/pre&gt;
&lt;p&gt;At first glance this is a so what... until you look at what it is really doing for me.&lt;/p&gt;
&lt;p&gt;I am looking at a Web Page that I need to extract a bunch of criteria from and many of them will most likely be blank, so why even loop through them?&amp;nbsp; The AndAlso takes care of any problems arising from controls that are not RadTextBox.&amp;nbsp; Additionally, I need to take the results and put them into a Dictionary so that I can pass this onto my Dynamic Query routine.&lt;/p&gt;
&lt;p&gt;The code this is replacing is about 30 lines of code (that I didn't write...) and I can see exactly what is going on in this concise format.&amp;nbsp; All I had to do is think a little different from the old habits of coding and apply some of the great new tools we have at our disposal.&amp;nbsp; What the Old code did was to loop through all the controls in the SearchCriteria DIV and check to see if .Text was filled, but to do that, it needed to cast the Control.&amp;nbsp; Then on top of that it needed to add the Dictionary Item.&lt;/p&gt;
&lt;p&gt;This new code could actually be written on one line, but for programming clarity and readability, I broke it up.&lt;/p&gt;
&lt;p&gt;Now this really reads easy and works perfectly, thanks to Linq.&amp;nbsp; A little refactoring and this could become a permanent addition to a Utilities class.&lt;/p&gt;
&lt;p&gt;nb: the Remove leverages the fact that I use "Find_&amp;lt;DBFieldName&amp;gt;" in markup and not have to resort to bindings or strings, it also makes this a candidate for a code generation template.&lt;/p&gt;&lt;img src ="http://blog.steeleprice.net/aggbug/1503.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>H. Steele Price, IV</dc:creator><title>EntityDB: The next great Microsoft tool (if they would just make it)</title><link>http://blog.steeleprice.net/archive/2008/05/20/1485.aspx</link><pubDate>Tue, 20 May 2008 15:38:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/05/20/1485.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1485.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/05/20/1485.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1485.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1485.aspx</trackback:ping><description>&lt;P&gt;Reading in the Industry blogs, official samples and documentation provided with MS SQL Server 2005+, Visual Studio 2008 and Linq to Sql and the Entity Framework, you will get the impression that we have a tremendous ability to efficiently decipher how to interact with a Database.&amp;nbsp; Additionally, Industry leaders have led us down a path of Code Generators, Designers and the separation of UI Design from functional Object code; read "Astoria" and/or "MVC" here...&lt;/P&gt;
&lt;P&gt;Didn't CASE do this sort of thing for us years ago?&amp;nbsp; Didn't it also fail?&amp;nbsp; There is huge amount of traffic about the topic of "Falling down when you hit a threshold" and insistence that all things should be built ultra-scalable.&amp;nbsp; OK, that's great if you love to write plumbing.&amp;nbsp; I for one, don't. What if that could be done for you, with the most efficient options always at your disposal; of course with the opportunity to tweak and extend to meet a specific need.&lt;/P&gt;
&lt;P&gt;While there are many great arguments to be had over what is exactly ultra-efficient and those who think they have a better method must be able to override and extend the selected generation of code that is offered by not only being able to write that code, but also to inject it into the Generated Code (or at the least allowed to edit the templates) produced by Visual Studio.&lt;/P&gt;
&lt;P&gt;If you don't already know why this is so important, we need to first look at the massive shift in Business Software Development and where we are going to be running most business applications.&amp;nbsp; We used to run all our apps on our own hardware, inside our own network and everything was under our tight control.&amp;nbsp; While this model still applies to much corporate development, I believe it will become less and less used as a cost effective alternative to a HOSTED solution.&amp;nbsp; Pricing of hosted solutions have plummeted in recent years, in fact I am almost willing to bet that the cost of electricity alone using hardware just a few years old would cover the cost of a hosted solution.&amp;nbsp; And what happens when I DO need to scale, How do I add 20 servers to the Web Farm overnight?&amp;nbsp; Staffing requirements and maintenance of hardware start to become totally offset when we look at this model. I CANNOT BUILD A SERVER CHEAPER THAN I CAN HOST ONE!&amp;nbsp; That is the real bottom line.&lt;/P&gt;
&lt;P&gt;I would wager that MOST applications would run just fine on a hosted solution with one machine doing all the work, at least in the beginning, or at least with a hoster that gives you Web on one machine and your DB on another.&amp;nbsp; Are we talking about every solution here?&amp;nbsp; No, but I think we are talking about a gigantic sector of the market that is currently all but ignored by the provided tools we have at our disposal.&lt;/P&gt;
&lt;P&gt;Don't get me wrong here, we have GREAT tools available and more coming, do they target what is really needed?&lt;/P&gt;
&lt;P&gt;First lets look at the three new primary tools given to us by Microsoft.&amp;nbsp; WCF, Linq to Sql and the Entity Framework.&amp;nbsp; WCF provides a great pipeline to pass data between our UI, Business Objects and Database, but it just plumbing.&amp;nbsp; Linq to Sql and EF provide a great way to interact with a Database IF and ONLY If you have a proper database in place first.&lt;/P&gt;
&lt;P&gt;What does this mean to most data-driven development projects?&amp;nbsp; It means they either need a DBA, or they need to hire one for the portion of the application that defines the database.&amp;nbsp; This is one reason &lt;A href="http://wiki.rubyonrails.org/rails/pages/understandingmigrations" target=_blank&gt;Migrations for Ruby on Rails&lt;/A&gt; has gained so much popularity, it hides this chore.&amp;nbsp; Most of us don't care about the DB, it's just a place that holds data.&amp;nbsp; Some of you can go on and on all day about the subtleties of databases but that is completely outside the scope of what I am talking about here. Not only will Migrations create a DB and Schema around what your App needs, it will also keep it up to date with changes made by any developer that can be easily stored in Version Control software like SVN or TFS.&lt;/P&gt;
&lt;P&gt;This is what the Designers for Linq to Sql and/or Entity Framework need to do for us.&amp;nbsp; I really don't mind changing my Linq to SQL Apps over to Entity Framework if it will allow us to focus on one great technology.&amp;nbsp; It's great that they can operate against a currently created database, but they should also create one (IN AN OPTIMIZED WAY) when one does not exist.&amp;nbsp; It should create Stored Procedures if I tell it to... Even if we are migrating a legacy application, I would still like to see what a tool spits out for me.&amp;nbsp; I just might use the new techniques.&amp;nbsp; There are tons of ways to move data from one schema to another, again, outside the scope of this article.&amp;nbsp; So back to the scope...&amp;nbsp; EF Does a great job of creating an interaction between Database and Business Objects, but it doesn't help us rapidly create a NEW model without an existing database and I think this is important in two ways, first and foremost, I don't want to write any plumbing code to do this.&amp;nbsp; The tools are smart enough already to do almost all the work for us, it can go just a little bit further and create the expected interaction that solves most of the interaction of the database work for us.&amp;nbsp; I can create a Model with the EF Designer by adding Properties and Associations, but it won't go and create a database around that model.&lt;/P&gt;
&lt;P&gt;I should not have to know about how the interaction happens, just that it does and that it does so in a fairly efficient manner.&amp;nbsp; If I lose a certain percentage of performance due to layers, then so be it if I can create my application 10 times faster.&amp;nbsp; If the tool developers choose to implement change tracking in a DataContext or Object Context that is great, do so in a way that makes sense for the CODE developers to use, not require me to go hire Database professionals to argue about the proper plumbing or storage techniques.&amp;nbsp; Linq ALREADY knows how to create efficient SQL, if it did so in code generation vs. dynamically at runtime who cares?&lt;/P&gt;
&lt;P&gt;We can host a solution out in the cloud so should we need to be worried about the optimization of how our application persists its data?&amp;nbsp; Certainly there is is need to cover legacy applications and all the DBAs running around out there, that is well covered right now.&amp;nbsp; What we seem to be missing is the ability for competent application developers to create Rich Internet Applications (read Silverlight and Ajax) and have the data persisted without a bunch of plumbing and tweaking.&lt;/P&gt;
&lt;P&gt;What is NOT covered is the ability to rapidly envision, design, develop and deploy solutions destined to live on a Hosted Solution -- even if it is "hosted" internally.&amp;nbsp; This solution will most likely have a distinct separation between UI, Business Objects and Database, but do I really need to see those distinctions in my code?&amp;nbsp; Not really.&amp;nbsp; Do I really need to spend the time to wire up all the Databinding when the MetaData already knows what I need to do?&amp;nbsp; No Way, a tool can create that for us.&amp;nbsp; It can already look into our metadata and see what we need to do to hook up a DataGridView to a table.&lt;/P&gt;
&lt;P&gt;I would venture to say that the tools are already here, they just don't work the way we need them to so we can build these applications quickly.&amp;nbsp; I spend MOST of my time Creating a Database, then working on plumbing and interactions between the Database and the UI, I should not have to do this any more.&amp;nbsp; Microsoft did a fabulous job of giving us a database that can scale with us as our application grows.&amp;nbsp; We have SQL CE, SQL Server Express and SQL Server Enterprise to grow with us, we can use SQL CE for Mobile Apps and offline stuff, wouldn't it be wonderful if I did not have to architect that portion of the solution any more?&amp;nbsp; I am talking about the people who do not have the luxury of a full time DBA.&lt;/P&gt;
&lt;P&gt;Of course, the solution is there, staring us right in the face, the answer is the Designer for Entity Framework.&amp;nbsp; If this Designer could be used to build out the Database, and track the Schema changes, then it would take down part of the battle, just a little more work and it could completely remove the NEED (we should always have the option to extend and modify though) for us to write anything between the Business Objects and the Database.&lt;/P&gt;
&lt;P&gt;We should not need to write Serializers for Silverlight, WCF or anything else, the tools already KNOW how to do that, they just don't.&amp;nbsp; The MetaData is there, let's use it.&amp;nbsp; Rob Conery's Subsonic and ActiveRecord shows there is interest in such a tool, but I say this tool needs to come from Microsoft and it needs to be built into the current generation of tools we are using or are being pushed to use (aka Linq).&amp;nbsp; With Rob and Phil working AT Microsoft why can't they contribute some of that knowledge over to the ADO team and get this into the EF Tools we need.&amp;nbsp; Pablo, Mike, Dinesh and the rest of the ADO Team are doing a great job so far, but they are only touching on what we really need.&amp;nbsp; The newest version of EF finally gets a way to do disconnected graphs which is a step towards the goal thanks to &lt;A href="http://blogs.msdn.com/dsimmons/" target=_blank&gt;Danny Simmons&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;These tools need to work seamlessly with Linq and allow me as a developer to write applications with little or no concern for how my data is persisting.&amp;nbsp; I want to create Controls that I can offer to my UI which work seamlessly with Ajax or Silverlight and not require me to write a ton of plumbing just to move things back and forth from one layer to another.&lt;/P&gt;
&lt;P&gt;This is the challenge for the new world of development.&amp;nbsp; We have already moved to a hosted world and our tools need to move there with us. But what do I know, I am a VB developer first and foremost... This is what I know, my customers are asking me to create these applications and to create them really fast.&amp;nbsp; I can choose to use the tools I know best or I can branch out and find something new.&amp;nbsp; The problem here is that I have already invested years of time to learn the tools I am using and they are simply not doing what I need them to do to make my job truly easier.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;My Invoice Object doesn't really need to know what DataContext my Customer Object lives in and I as a developer should not have to be concerned about that in the slightest.&amp;nbsp; I should be able to freely take a Customer I loaded from Invoice "A" and assign it to be used for Invoice "B" without worrying what context it came from, Invoice "B" just needs to know its a valid Customer or that it is a new one I just created without me forcing something into the plumbing to test it.&amp;nbsp; It should know how to roll itself back when I cancel changes, etc.&lt;/P&gt;
&lt;P&gt;With Generics and XML Literals, VB is a Top Notch Code Generator.&amp;nbsp; &lt;A href="http://msmvps.com/blogs/kathleen/" target=_blank&gt;Kathleen has proven that here&lt;/A&gt; and &lt;A href="http://karlshifflett.wordpress.com/2008/03/02/visual-studio-2008-designers-and-code-generators-you-have-overlooked/" target=_blank&gt;Karl talks about Metadata and what we can do with it over here&lt;/A&gt;... We don't need Yet Another Code Generator.&amp;nbsp; We need something that works with the existing modelers and designers and just makes our life as developers easier.&amp;nbsp; It needs to be INSIDE Visual Studio and we need to be able to work with the templates.&amp;nbsp; I should not need LLBLGen or MyGeneration or CodeSmith or SubSonic to do something Visual Studio pretty much already knows HOW to do, it just doesn't.&amp;nbsp; I don't need another designer that works with an existing database, I need the CURRENT Designers to Make the Database AND the plumbing.&lt;/P&gt;
&lt;P&gt;I personally think this should be the direction for the next revision of Visual Basic.&amp;nbsp; VB IS the glue that puts the framework together, sure you could also do it in C# (if they added XML Literals...) but VB is already geared for it so why not enhance it's productivity even further by giving us a way to be far more productive than we are today.&amp;nbsp; This does not require any great shift in the tools we already have, it just requires Microsoft to use them smarter and provide us the keys we need to open the door.&lt;/P&gt;&lt;img src ="http://blog.steeleprice.net/aggbug/1485.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>H. Steele Price, IV</dc:creator><title>Introducing LINQ To Regex</title><link>http://blog.steeleprice.net/archive/2008/05/08/1409.aspx</link><pubDate>Thu, 08 May 2008 10:59:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/05/08/1409.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1409.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/05/08/1409.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1409.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1409.aspx</trackback:ping><description>&lt;p&gt;Roy gives us 2 great things here:&amp;nbsp;&amp;nbsp; An easier to understand Regex for people who don't care to learn the ins and outs of regex AND more importantly an example of how to build a Linq Provider.&amp;nbsp; I may tap into this idea for producing a couple Linq Providers I am thinking about, such as Linq to RSS and Linq to NNTP, alas, I really don't want to be a plumber this month so I am hoping someone beats me to the idea for Linq to NNTP which I could really use :-)&lt;/p&gt; &lt;blockquote&gt; &lt;h4&gt;Introducing LINQ To Regex&lt;/h4&gt; &lt;p&gt;When I first saw &lt;a href="http://flimflan.com/blog/ReadableRegularExpressions.aspx"&gt;Josh Flanagan's Readable Fluent Regex Api&lt;/a&gt;, I loved it at first sight. Now I'm working on a demo for the &lt;a href="http://www.devteach.com/"&gt;upcoming DevTeach in Toronto&lt;/a&gt;, where I'll present how to build custom LINQ providers to various things. &lt;p&gt;I thought it would be interesting to see if using the fluent Regex API Josh created along with a LINQ query syntax would "work" for me, so I set out to create LINQ to Regex.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2008/05/06/introducing-linq-to-regex.aspx"&gt;Introducing LINQ To Regex on Roy Osherove's Blog&lt;/a&gt;&lt;/p&gt;&lt;img src ="http://blog.steeleprice.net/aggbug/1409.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>H. Steele Price, IV</dc:creator><title>Utility for building Linq Queries</title><link>http://blog.steeleprice.net/archive/2008/05/08/1408.aspx</link><pubDate>Thu, 08 May 2008 10:35:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/05/08/1408.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1408.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/05/08/1408.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1408.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1408.aspx</trackback:ping><description>&lt;blockquote&gt; &lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/vlinq" target="_blank"&gt;Visual LINQ Query Builder&lt;/a&gt; is an add-in to Visual Studio 2008 Designer that helps you visually build LINQ to SQL queries. Functionally it provides the same experience as, for instance the Microsoft Access Query Builder, but in the LINQ domain. The entire UI of this add-in uses Windows Presentation Foundation. The goal of this tool is to help users become more familiar with the LINQ syntax. The tool may also demonstrate to users how to create their own Visual Studio 2008 add-in using Windows Presentation Foundation.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is very helpful in letting you see the big picture when you have particularly complex queries.&amp;nbsp; I'd really like to see this integrated with something like LinqPad so we could get a better look at how we can structure Linq Queries.&amp;nbsp; I'd also like to see this not need to add something to your Project just to use it, that is a real turn off for me, but you can always delete it when you are done.&amp;nbsp; This is a good effort though on helping to simplify understanding new technologies.&amp;nbsp; I'd also like to see it brach out to support more than Linq to Sql.&lt;/p&gt; &lt;p&gt;On the positive side, this does have a pretty good visual appearance in VS08 and I like how it is put together, building queries is pretty easy to do with the leveraging of intellisense.&amp;nbsp; Some big missing items re Grouping and Aggregates, those tend to be the more difficult queries to visualize and where this tool would be most useful.&lt;/p&gt; &lt;p&gt;I would place this in the beginner category though because it will tend to get in the way of a seasoned Linq developer.&lt;/p&gt;&lt;img src ="http://blog.steeleprice.net/aggbug/1408.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>H. Steele Price, IV</dc:creator><title>Change Tracking with Linq to SQL</title><link>http://blog.steeleprice.net/archive/2008/05/05/1405.aspx</link><pubDate>Mon, 05 May 2008 10:11:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/05/05/1405.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1405.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/05/05/1405.aspx#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1405.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1405.aspx</trackback:ping><description>&lt;p&gt;While I am doing this in a VERY Different way... it is worth mentioning the &lt;a href="http://www.codeplex.com/ULinqGen/" target="_blank"&gt;Unplugged LINQ to SQL Generator&lt;/a&gt; which is available on CodePlex: &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://pampanotes.tercerplaneta.com/2008/03/implementing-n-tier-change-tracking.html"&gt;http://pampanotes.tercerplaneta.com/2008/03/implementing-n-tier-change-tracking.html&lt;/a&gt; &lt;/p&gt; &lt;p&gt;When designing our application data model, we think some of our entities as an in-memory cache of small pieces of data living in a database (MSSQL, Oracle, Xml files, etc.). This data will be jumping between both worlds.&lt;/p&gt; &lt;p&gt;To keep this "cache" synchronized, we need mechanisms to read data from storage, and update changes back, to perform that we create CRUD operations.&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;h5&gt;&lt;a href="http://pampanotes.tercerplaneta.com/2008/03/how-to-use-unplugged-linq-to-sql.html"&gt;How to use the Unplugged LINQ to SQL Generator&lt;/a&gt;&lt;/h5&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;As &lt;a href="http://rocksthoughts.com/blog/Default.aspx"&gt;Chris Rock&lt;/a&gt; pointed out, the first release of our Code Project &lt;a href="http://www.codeplex.com/ULinqGen"&gt;custom tool&lt;/a&gt; for LINQ to SQL code generation lacks any usage documentation. &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I am not sure this is the approach I want to take, but it does have some interesting possibilities. &lt;p&gt;I am in the process of writing up the way I am approaching this &lt;strong&gt;&lt;em&gt;EXACT SAME DILEMNA&lt;/em&gt;&lt;/strong&gt; in a different way; I am using inheritance of&amp;nbsp; Generic Base Class to accomplish pretty much the same thing.&amp;nbsp; The difference in my approach is that there is no need to do any CodeGen outside the regular way that Linq To SQL already does it, it's just there.&amp;nbsp; This also has pluses and minuses so maybe a combination of the two is in order.&amp;nbsp; &lt;p&gt;Of course, Mine is also in VB not just C#...&lt;img src ="http://blog.steeleprice.net/aggbug/1405.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>H. Steele Price, IV</dc:creator><title>Mocks Nix - An Extensible LINQ to SQL DataContext</title><link>http://blog.steeleprice.net/archive/2008/05/05/1404.aspx</link><pubDate>Mon, 05 May 2008 10:00:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/05/05/1404.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1404.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/05/05/1404.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1404.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1404.aspx</trackback:ping><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/user/Profile.aspx?UserID=3134"&gt;mattwar&lt;/a&gt; tell us the proper way to0 "extend"&amp;nbsp; DataContext in Linq to SQL. &lt;p&gt;"I often get asked how LINQ to SQL is supposed to be used with Test Driven Design (TDD). &lt;p&gt;LINQ to SQL was actually designed to be host to more types of back-ends than just SQL server. It had a provider model targeted for RTM, but was disabled before the release."&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I am still reading this, some of it looks good, some of it looks not so good... &lt;blockquote&gt; &lt;p&gt;&lt;b&gt;&lt;i&gt;DISCLAIMER: Overriding internal implementation details is not a practice recommend or supported by Microsoft. Implementation details are subject to change without warning.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I am not sure that extending the DataContext is really what I need to do for my "Entities with State" model, but I am willing to look at it in that respect. &lt;p&gt;I think I still prefer what I am doing, ignoring most of the stuff the DataContext tries to help with (in a totally connected type of way...) and move those things to the Entity so I can be completely disconnected much easier.&lt;/p&gt;&lt;img src ="http://blog.steeleprice.net/aggbug/1404.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>H. Steele Price, IV</dc:creator><title>DebuggerWriter for Linq to SQL</title><link>http://blog.steeleprice.net/archive/2008/05/01/1401.aspx</link><pubDate>Thu, 01 May 2008 13:12:00 GMT</pubDate><guid>http://blog.steeleprice.net/archive/2008/05/01/1401.aspx</guid><wfw:comment>http://blog.steeleprice.net/comments/1401.aspx</wfw:comment><comments>http://blog.steeleprice.net/archive/2008/05/01/1401.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blog.steeleprice.net/comments/commentRss/1401.aspx</wfw:commentRss><trackback:ping>http://blog.steeleprice.net/services/trackbacks/1401.aspx</trackback:ping><description>&lt;p&gt;I needed to find out exactly what was being submitted by DataContext.SubmitChanges and didn't want to use SQL Profiler.&lt;/p&gt; &lt;p&gt;I ran across &lt;a href="http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11" target="_blank"&gt;this post by Kris Vandermotten&lt;/a&gt; and have converted the code to VB for anyone else who may need it.&lt;/p&gt; &lt;p&gt;This is now always in my Utility.vb file that gets attached to most of my projects. &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="vbcode"&gt;    
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Diagnostics
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Globalization
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.IO
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Text
&lt;br&gt;
&lt;span class="rem"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;''' Implements a &amp;lt;see cref="TextWriter"/&amp;gt; for writing information to the debugger log.&lt;/span&gt;
    &lt;span class="rem"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;''' &amp;lt;seealso cref="Debugger.Log"/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; DebuggerWriter
        &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; TextWriter
        &lt;span class="kwrd"&gt;Private&lt;/span&gt; _isOpen &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
        &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; _encoding &lt;span class="kwrd"&gt;As&lt;/span&gt; UnicodeEncoding
        &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; _level &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
        &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; _category &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;

        &lt;span class="rem"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' Initializes a new instance of the &amp;lt;see cref="DebuggerWriter"/&amp;gt; class.&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;()
            &lt;span class="kwrd"&gt;Me&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(0, Debugger.DefaultCategory)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="rem"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' Initializes a new instance of the &amp;lt;see cref="DebuggerWriter"/&amp;gt; class with the specified level and category.&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;param name="level"&amp;gt;A description of the importance of the messages.&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;param name="category"&amp;gt;The category of the messages.&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; level &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; category &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;)
            &lt;span class="kwrd"&gt;Me&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(level, category, CultureInfo.CurrentCulture)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="rem"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' Initializes a new instance of the &amp;lt;see cref="DebuggerWriter"/&amp;gt; class with the specified level, category and format provider.&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;param name="level"&amp;gt;A description of the importance of the messages.&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;param name="category"&amp;gt;The category of the messages.&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;''' &amp;lt;param name="formatProvider"&amp;gt;An &amp;lt;see cref="IFormatProvider"/&amp;gt; object that controls formatting.&amp;lt;/param&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; level &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; category &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; formatProvider &lt;span class="kwrd"&gt;As&lt;/span&gt; IFormatProvider)
            &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(formatProvider)
            &lt;span class="kwrd"&gt;Me&lt;/span&gt;._level = level
            &lt;span class="kwrd"&gt;Me&lt;/span&gt;._category = category
            &lt;span class="kwrd"&gt;Me&lt;/span&gt;._isOpen = &lt;span class="kwrd"&gt;True&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="kwrd"&gt;Protected&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Dispose(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; disposing &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;)
            _isOpen = &lt;span class="kwrd"&gt;False&lt;/span&gt;
            &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.Dispose(disposing)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Write(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Char&lt;/span&gt;)
            &lt;span class="kwrd"&gt;If&lt;/span&gt; &lt;span class="kwrd"&gt;Not&lt;/span&gt; _isOpen &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                &lt;span class="kwrd"&gt;Throw&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; ObjectDisposedException(&lt;span class="kwrd"&gt;Nothing&lt;/span&gt;)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
            Debugger.Log(level, category, value.ToString())
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Write(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;)
            &lt;span class="kwrd"&gt;If&lt;/span&gt; &lt;span class="kwrd"&gt;Not&lt;/span&gt; _isOpen &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                &lt;span class="kwrd"&gt;Throw&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; ObjectDisposedException(&lt;span class="kwrd"&gt;Nothing&lt;/span&gt;)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
            &lt;span class="kwrd"&gt;If&lt;/span&gt; value &amp;lt;&amp;gt; &lt;span class="kwrd"&gt;Nothing&lt;/span&gt; &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                Debugger.Log(level, category, value)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Write(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; buffer &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Char&lt;/span&gt;(), &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; index &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; count &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;)
            &lt;span class="kwrd"&gt;If&lt;/span&gt; &lt;span class="kwrd"&gt;Not&lt;/span&gt; _isOpen &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                &lt;span class="kwrd"&gt;Throw&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; ObjectDisposedException(&lt;span class="kwrd"&gt;Nothing&lt;/span&gt;)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
            &lt;span class="kwrd"&gt;If&lt;/span&gt; buffer = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt; &lt;span class="kwrd"&gt;OrElse&lt;/span&gt; index &amp;lt; 0 &lt;span class="kwrd"&gt;OrElse&lt;/span&gt; count &amp;lt; 0 &lt;span class="kwrd"&gt;OrElse&lt;/span&gt; buffer.Length - index &amp;lt; count &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                &lt;span class="rem"&gt;' delegate throw exception to base class&lt;/span&gt;
                &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.Write(buffer, index, count)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
            Debugger.Log(level, category, &lt;span class="kwrd"&gt;New&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;(buffer, index, count))
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Overloads&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Encoding() &lt;span class="kwrd"&gt;As&lt;/span&gt; Encoding
            &lt;span class="kwrd"&gt;Get&lt;/span&gt;
                &lt;span class="kwrd"&gt;If&lt;/span&gt; _encoding &lt;span class="kwrd"&gt;Is&lt;/span&gt; &lt;span class="kwrd"&gt;Nothing&lt;/span&gt; &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                    _encoding = &lt;span class="kwrd"&gt;New&lt;/span&gt; UnicodeEncoding(&lt;span class="kwrd"&gt;False&lt;/span&gt;, &lt;span class="kwrd"&gt;False&lt;/span&gt;)
                &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
                &lt;span class="kwrd"&gt;Return&lt;/span&gt; _encoding
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Level() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Integer&lt;/span&gt;
            &lt;span class="kwrd"&gt;Get&lt;/span&gt;
                &lt;span class="kwrd"&gt;Return&lt;/span&gt; Level
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;ReadOnly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Category() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;
            &lt;span class="kwrd"&gt;Get&lt;/span&gt;
                &lt;span class="kwrd"&gt;Return&lt;/span&gt; _category
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To use this for troubleshooting DataContext issues simply set the DataContext.Log = New DebuggerWriter such as this:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; tran &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Transactions.TransactionScope
Using tran
    db.Log = &lt;span class="kwrd"&gt;New&lt;/span&gt; DebuggerWriter
    db.SubmitChanges(ConflictMode.ContinueOnConflict)
    &lt;span class="rem"&gt;'rollback by disposing without complete&lt;/span&gt;
    tran.Dispose()
&lt;span class="kwrd"&gt;End&lt;/span&gt; Using
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This will submit the changes, spit out all the SQL code to the Debugger Window and roll everything back.&lt;/p&gt;&lt;img src ="http://blog.steeleprice.net/aggbug/1401.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>