<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/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>WCF</title>
        <link>http://www.shanghai-software.com/blog/category/5.aspx</link>
        <description>WCF</description>
        <language>en-AU</language>
        <copyright>Ben Kloosterman</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>WS-Eventing flaw </title>
            <link>http://www.shanghai-software.com/blog/archive/2009/02/15/ws-eventing-flaw.aspx</link>
            <description>Just doing some work on eventing and having a look at a number of implementations there is a pretty annoying feature / flaw .&lt;br /&gt;
&lt;br /&gt;
By default the only filter supported is Xpath and the specification specifically states that&lt;br /&gt;
&lt;br /&gt;
This specification does not constrain notifications because any message MAY be a notification. from &lt;a href="javascript:void(0);/*1234671797014*/"&gt;http://www.w3.org/Submission/WS-Eventing/. &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I have no issues for this - sometimes you want any message , however this is a very expensive way to do this especially when you have a large amount of events with different topics all coming through a single  notification service ( load balanced) . &lt;br /&gt;
&lt;br /&gt;
All the implementations i have seen ( including the sample in the specification ) introduce the concept of a topic to route the data.  &lt;br /&gt;
&lt;br /&gt;
eg &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Sample in spec uses a header &lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;    &amp;lt;ow:EventTopics&amp;gt;weather.report weather.storms&amp;lt;/ow:EventTopics&amp;gt; &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;and a custom filter &lt;/p&gt;
&lt;pre&gt; &amp;lt;wse:Filter xmlns:ow="http://www.example.org/oceanwatch"&lt;br /&gt;(43)           Dialect="http://www.example.org/topicFilter" &amp;gt;&lt;br /&gt;(44)         weather.storms&lt;br /&gt;(45)       &amp;lt;/wse:Filter&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style="font-weight: bold;"&gt;MSE ( Managed Service Engine from Mi&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;crosoft) &lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-weight: bold;" /&gt;Uses a custom filter  http://services.microsoft.com/2006-07/ServicePlatform/MSE6/Eventing/EventFilter/    which includes topics in the body of their custom event message.&lt;br /&gt;
&lt;/p&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;span style="font-weight: bold;"&gt;Roman kiss implementation&lt;/span&gt; includes a string topic in his subscribe message and has one topic per notification end point.&lt;br /&gt;
&lt;br /&gt;
The end result is everyone will build there own system and filters. &lt;br /&gt;
&lt;br /&gt;
Basically all the authors recognize that  the default spec will have performance issues and can be easily optomized ;  So why didnt the spec include an optional header on notifications and a simple canonical topic/subtopic  filter ? This way the majority of eventing systems can talk to each other without resorting to XPath. &lt;br /&gt;
&lt;br /&gt;
 &lt;img src="http://www.shanghai-software.com/blog/aggbug/33.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/02/15/ws-eventing-flaw.aspx</guid>
            <pubDate>Sun, 15 Feb 2009 04:39:47 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/33.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/02/15/ws-eventing-flaw.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/33.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/33.aspx</trackback:ping>
        </item>
        <item>
            <title>What is Azure Services ?</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/02/07/what-is-azure-services.aspx</link>
            <description>Are Azure services a cloud or are they an ESB ? &lt;br /&gt;
&lt;br /&gt;
While Azure does not have this it has FAR more than most ESB in terms of connecting clients to services. Sure it has router support &lt;br /&gt;
&lt;br /&gt;
Azure &amp;gt;&amp;gt; ESB  (Internet hosted , with integrated  internet security , scalable) &lt;br /&gt;
Azure &amp;gt;&amp;gt; Cloud computing  ( not just Client - Service routing and hosting but also it has sender-receiver relay , multicast , firewall pass through ,   and enterprise-cloud security integration)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The big thing is people see it as a cloud .. however i think the biggest thing is it can redirect clients requests into your internal systems ( or partners!) in a secure manner with a global logon.  Or facilitate secure communication between clients and companies ( as well as B2B) &lt;br /&gt;
&lt;br /&gt;
A lot of people say the Enterprise will not put services in the cloud - i dispute this.  VPNs are used to drive many branch offices which was not done earlier its a question how comfortable they are with the management and security.  Like outsourcing to india.&lt;img src="http://www.shanghai-software.com/blog/aggbug/28.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/02/07/what-is-azure-services.aspx</guid>
            <pubDate>Sat, 07 Feb 2009 02:21:46 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/28.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/02/07/what-is-azure-services.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/28.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/28.aspx</trackback:ping>
        </item>
        <item>
            <title>SO Analysis</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/02/05/so-analysis.aspx</link>
            <description>&lt;br /&gt;
&lt;br /&gt;
Lots of books and posts have been written but IMHO they fail miserably.&lt;br /&gt;
- They involve a new language/diagram &lt;br /&gt;
- They use propriatry tools&lt;br /&gt;
- Focus heavily on BPEL and you need services to drive the BPEL (mmm) &lt;br /&gt;
- They are overly complex. and hence violate the  most important rule KISS. &lt;br /&gt;
&lt;br /&gt;
I prefer a loose guideline like the following. &lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
    &lt;li&gt;Consider the large-grained logical services your systems represent (such as Accounting, Sales, Manufacturing, Design)&lt;/li&gt;
    &lt;li&gt;Ignoring political / divisional boundaries, consider each large-grained logical service and conceptualize how it should be broken up into finer and finer grained services (Accounting could be factored into Purchasing, Banking, Operational Finance, Expenses, HR Finance, etc)&lt;/li&gt;
    &lt;li&gt;Repeat 1 and 2 until you have a fairly detailed map of the system under consideration. Remember, Services are fractal - one service decomposes into more services which decompose into more services ...&lt;/li&gt;
    &lt;li&gt;Now, (again, ignoring political / divisional boundaries) try and identify common shared services - even though they may presently be siloed duplicates. Now consider what your system would look like if they were all consolidated into a single service instance (which of course may publish one or many service interfaces and the associated methods)&lt;/li&gt;
    &lt;li&gt;After consolidating as much as makes sense, map out the kinds of message exchange patterns between services. One-way (fire and forget), Request-Reply (blocking calls), Full Duplex (bi-directional async). Don't focus on transports or protocols here, talk about the higher order semantics "this link needs to be secure", "this link needs to be reliable", etc.&lt;/li&gt;
    &lt;li&gt;Refactor services  so services that communicate frequently are upscaled eg if you have a Order service and seperate service for OrderItems refactor them into the same service&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Now map out the data structures that should be passed between services when actions are requested and the responses when complete.&lt;/li&gt;
    &lt;li&gt;Now consider what will be your organization's strategy for inter-service communications? Are you homogenous? What is the strategic direction of the platform(s) on which you build systems? If you have to interop, what will be your strategic direction? Remember, whatever lies INSIDE a service is irrelevant to the outside world, so let's not consider service internals here.&lt;/li&gt;
    &lt;li&gt;Once you know how your services will hang together, you can then start deciding on how to wrap/expose existing systems to the outside world, and where and with whom you want to bet on strategically to deliver the platform(s) for your future needs.&lt;/li&gt;
    &lt;li&gt;Wrap existing services before writing new ones.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
based on Richart Turners original post&lt;img src="http://www.shanghai-software.com/blog/aggbug/26.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/02/05/so-analysis.aspx</guid>
            <pubDate>Thu, 05 Feb 2009 05:15:17 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/26.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/02/05/so-analysis.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/26.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/26.aspx</trackback:ping>
        </item>
        <item>
            <title>Is SOA a Belief system and what does that mean for Team dynamics</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/02/05/is-soa-a-belief-system-and-what-does-that-mean.aspx</link>
            <description>&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Best SOA posts on the net ( and the comments) &lt;br /&gt;
&lt;br /&gt;
http://blogs.msdn.com/richardt/archive/2005/12/13/503358.aspx&lt;br /&gt;
&lt;br /&gt;
This is what I believe SO is ... it truly is a belief system and a way of thinking. It is not a prescriptive architectural process or methodology. It's not a template that you can apply that results in a service oriented system. It's where art meets science. It's where aesthetics meets engineering. It's the thing adds a human touch to the things we create. It's inside of me and it's inside of you....&lt;br /&gt;
&lt;br /&gt;
&lt;h4 class="CommentTitle"&gt; 				&lt;a id="ctl00___ctl00___ctl02___Comments___Comments_ctl01_NameLink" title="james governor" rel="nofollow" href="http://www.redmonk.com/jgovernor"&gt;james governor&lt;/a&gt;  				said: 				&lt;img align="absbottom" alt="" src="http://blogs.msdn.com/Themes/Blogs/paperclip/images/spacer.gif" class="CommentArrow" /&gt; 			&lt;/h4&gt;
&lt;div class="CommentText"&gt;
&lt;div class="CommentText2"&gt;
&lt;div class="CommentText3"&gt;i am with anil. a call for an epiphany is kind of hard. you ever read any wittgenstein? &lt;br /&gt;
&lt;br /&gt;
"My propositions are elucidatory in this way: he who understands me finally recognizes them as senseless, when he has climbed out through them, on them, over them. (He must so to speak throw away the ladder, after he has climbed up on it.)" &lt;br /&gt;
&lt;br /&gt;
this kind of intellectual bootstrapping is an issue. also - how many people ever "got" objects. you are making an argument for a priesthood, not a revolution in software productivity. &lt;br /&gt;
&lt;br /&gt;
i see too much of this from the vast IQs at Redmond. you guys need to understand not everyone is as smart as you are, and not everyone writes the kind of beautiful code you aspire too. You build tools for the masses, not for the geniuses eh.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style="font-style: italic;"&gt; &lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;h4 style="font-style: italic;" class="CommentTitle"&gt; 				&lt;a id="ctl00___ctl00___ctl02___Comments___Comments_ctl03_NameLink" title="Ben Kloosterman "&gt;Ben Kloosterman &lt;/a&gt;  				said: 				&lt;img align="absbottom" alt="" src="http://blogs.msdn.com/Themes/Blogs/paperclip/images/spacer.gif" class="CommentArrow" /&gt; 			&lt;/h4&gt;
&lt;div class="CommentText"&gt;
&lt;div class="CommentText2"&gt;
&lt;div class="CommentText3"&gt;&lt;span style="font-style: italic;"&gt;I do agree you need to make the leap , if you have not build distributed systems before ( remoting , Corba/ RMI or web service) you will not know why it is needed. Too many variables to explain which means you will never convince people. &lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;A bit Like TDD in the OO space ( and OO at first) people just have to try it .  &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 I wrote this in 2004 ( 5 years ago now !) and i still believe this, jumping to SOA is a leap and unfortunately some people who have not done distributed apps before have to learn through pain . As James rightly points out though many people nevery made the jump to OO which ALSO requires a leap of faith. With OO the industry has different ideas how high to leap . &lt;br /&gt;
&lt;br /&gt;
That being said i think the best thing is to design for the skills of the team !  A small app is probably best represented by 2 Tier database. A large distr. app or SOA environment is going to have people with all varieties of skills.  People with good OO skills can create complicated clients , framework , services etc , people with distributed app experiences can write the contracts , framework and services , VB Procedural programmers can write clients that consume the services.  In all cases because SOA services have a SIMPLE interface ( if designed well) and treat the services information as data all people can use it including different languages. In that sense organisations do not need to standardise as much as earlier . Most importantly people dont need to make the LEAP to SOA they can keep doing what they are comfortable with and willing to learn.  With Distributed Objects you needed a lot of people to have great OO and distributed app skills a pretty big ask  for most organisations. This is a big improvement.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://www.shanghai-software.com/blog/aggbug/21.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/02/05/is-soa-a-belief-system-and-what-does-that-mean.aspx</guid>
            <pubDate>Thu, 05 Feb 2009 03:37:11 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/21.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/02/05/is-soa-a-belief-system-and-what-does-that-mean.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/21.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/21.aspx</trackback:ping>
        </item>
        <item>
            <title>DTO pattern</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/02/05/dtopattern.aspx</link>
            <description>&lt;br /&gt;
http://msdn.microsoft.com/en-us/library/ms978717.aspx&lt;br /&gt;
http://martinfowler.com/eaaCatalog/dataTransferObject.html&lt;br /&gt;
&lt;br /&gt;
I still think Martin Fowlers description is best &lt;br /&gt;
&lt;font size="4"&gt;&lt;br /&gt;
&lt;/font&gt;&lt;em&gt;&lt;font size="4"&gt;An object that carries data between processes in order to reduce the number of method calls.&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/em&gt;While DTOs were designed for the above they provide key benefits to distributed systems&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;1.Performance&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Typically Objects in OO have quite a chatty interface , this is good for design purposes as these communication mirror the relationships between the objects however the performance implications for distributed systems are significant and worse the worry about performance last mentality in software development makes a significant issue as these issues are VERY expensive to fix as the design from the start is flawed. A simple example is Order and OrderItem while an order with a thousand line items may iterated the Items in memory in a microsecond  ( say to addup the total) ,  in a distributed system  with OrderItems in a different service this could take seconds (or more) . Much better to send all the Orders and OrderItems in one operation and then do the work required. While this is an obvious example most real life systems will have MANY issues with such chattiness which are not so easy to deal with. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;2.Remove Leaky abstraction  from &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;your domain model and hence improve maintenance&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;Another benefit of DTO's is they preserve your business logic from contamination by the needs of the outside world and hence make the system more easy to maintain. The performance issue mentioned above is one. Another common one is since you maybe communicating with other systems a change may be required in your system which if you are not using DTOs will propogate through the whole system ( eg support for DateTime? instead of Datetime for a Java client) . Its best to have a DTO be responsible for serializing the class ( and deal with the limitations of the transport eg XML). Is your Order class really responsible for its wire representation so why make it so ? &lt;a title="WCF" href="http://74.55.152.210/blog/WCF" rel=""&gt;Windows Communication Foundation&lt;/a&gt; doesn't support generics why limit your domain model by not allowing them , this is a perfect example of &lt;span style="font-weight: bold;"&gt;the leak abstraction &lt;/span&gt;you get with distributed systems - All such frameworks leak and hence you violate the basic OO rules of responsibility. Clearly your domain objects should NOT be responsible for working with the communications framework (whether EJB , &lt;a title="WCF" href="http://74.55.152.210/blog/WCF" rel=""&gt;Windows Communication Foundation&lt;/a&gt; etc) or underlying data ( eg XML)  &lt;br /&gt;
so why make it so?  Also note communication errors can occur in the middle of you business logic code ? Is it the responsibility for this code ? Preserving your domain model as designed will make it easier to maintain your code&lt;span style="font-weight: bold;"&gt;.  Leave the DTOs/Fascade to handle the real world.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;3. Appropriateness of Domains &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
All systems have different ideas of  what a "Person" or "Car" is , while a single application domain does not have this issue as much the more clients and services you get the more it becomes an issue. This is especially true of SOA systems. By treating the information from the server as Data ( and Procedures) each application can have a unique view of what a "Person" and "Car" is and hence map its solution closer to its real world model rather than trying to force the real world model for a new part of the system onto the current application.   This is not really a DTO benefit but DTO's allow the more completes seperation of logic  eg the sever converts the DTO to its logic and the client does likewise.  &lt;br /&gt;
&lt;br /&gt;
For example with  a client UI by exposing Domain objects to View layer, Views become aware of structure of domain objects, which lets the view make some assumptions about how related objects are available. For example if a domain object "Person" was returned to a view to which it is "bound" and on some other view, "Address" of Person is to be bound, there would be a tendency for Application layer to use a semantic like person.getAddresse() which would fail since at that point Address domain object might have not been loaded at point. In essence ( or require more chatty communication via lazy loading) , with domain objects becoming available to View layers, views can always make assumptions about how data is made available. Also the reverse when domain objects are bound to views (more so in Thick clients), there will always be a tendency for View centric logic to creep inside these objects making them logically corrupt. (note the similarity with the above messaging framework /wire transfer logic creeping in) &lt;br /&gt;
&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Easier to Maintain , better performance so why are DTO''s  rarely used in a lot of systems ?  &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;People seem obssessed with using tools and most tools ( and a lot of design methodologies) are focused in an idealized world and like to use the same object throughout the distributed system.  However real world practicalities then quickly reduce the quality of the domain model code. Such as focusing with serialization issues etc .&lt;br /&gt;
&lt;br /&gt;
There are issues with use of DTO's also since use of DTO creates additional work in terms of creation of Assemblers (DTO to Domain objects and reverse), Proliferation of analogous objects like Patient domain object, Patient DTO ,PatientDTOConverter  ,PatientView ( if not directly bound) . However note each of these Patient domains has a clear roll and the objects themselves are easy to create. &lt;br /&gt;
&lt;br /&gt;
I think DTOs should be used in ALL services unless you can write the service in a few days. Small anemic domains do not require them.&lt;img src="http://www.shanghai-software.com/blog/aggbug/20.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/02/05/dtopattern.aspx</guid>
            <pubDate>Thu, 05 Feb 2009 02:17:21 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/20.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/02/05/dtopattern.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/20.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/20.aspx</trackback:ping>
        </item>
        <item>
            <title>LINQ for SQL thread affinity Data context</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/01/15/linq-for-sql-thread-affinity-data-context.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://www.west-wind.com/Weblog/default.aspx"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;From &lt;font face="Arial"&gt;&lt;a href="http://www.cnblogs.com/sunrack/articles/1130866.html"&gt;http://www.cnblogs.com/sunrack/articles/1130866.html&lt;/a&gt; , for services we use mainly Thread Context ( the original allows a static context as well ). &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Thread context is very usefull for services.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;font size="2"&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;TDataContext result = (TDataContext)&lt;/div&gt;
&lt;div&gt;SetOptions(result); &lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;TDataContext result = (TDataContext)&lt;/div&gt;
&lt;div&gt;SetOptions(result);&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;options.LoadWith&amp;lt;&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div&gt;context.LoadOptions = options;&lt;/div&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;key = &lt;/div&gt;
&lt;div /&gt;
&lt;div /&gt;
&lt;div /&gt;
&lt;div&gt;context = &lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;context = GetDataContext();&lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div&gt;context = GetDataContext(ConnectionString);&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;threadData = &lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;{&lt;/div&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div /&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&lt;font size="2"&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; This class provides several static methods for loading DataContext objects &lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; in a variety of ways. You can load the data context as normal one new instance&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; at a time, or you can choose to use one of the scoped factory methods that&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; can scope the DataContext to a WebRequest or a Thread context (in a WinForm app&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; for example).&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Using scoped variants can be more efficient in some scenarios and allows passing&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; a DataContext across multiple otherwise unrelated components so that the change&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; context can be shared. &lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;DataContextFactory&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;lt;TDataContext&amp;gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;where&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;DataContext&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;()&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Creates a new Data Context for a specific DataContext type with a connection string&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Provided merely for compleness sake here - same as new YourDataContext()&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="connectionString"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetDataContext(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; connectionString)&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Type&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; t = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(TDataContext);&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Activator&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.CreateInstance(t, connectionString);&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; result; &lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Creates a new Data Context for a specific DataContext type&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Provided merely for compleness sake here - same as new YourDataContext()&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetDataContext()&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Type&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; t = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;typeof&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(TDataContext);&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Activator&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.CreateInstance(t);&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; result; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; SetOptions(TDataContext context)&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;DataLoadOptions&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; options = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;DataLoadOptions&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;();&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Force&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;gt;(Force =&amp;gt; Force.Characters); &lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;//add more rows&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Creates a Thread Scoped DataContext object that can be reused.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; The DataContext is stored in Thread local storage.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="key"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetThreadScopedDataContext()&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (TDataContext)GetThreadScopedDataContextInternal(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Creates a Thread Scoped DataContext object that can be reused.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; The DataContext is stored in Thread local storage.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="key"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetThreadScopedDataContext(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; key)&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (TDataContext)GetThreadScopedDataContextInternal(key, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Creates a Thread Scoped DataContext object that can be reused.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; The DataContext is stored in Thread local storage.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="key"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;object&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; GetThreadScopedDataContextInternal( &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; key, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; ConnectionString)&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (key == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;"__WRSCDC_"&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; + &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thread&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.CurrentContext.ContextID.ToString();&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;LocalDataStoreSlot&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; threadData = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thread&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.GetNamedDataSlot(key);&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;object&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; context = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (threadData != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thread&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.GetData(threadData);&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (context == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (ConnectionString == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;else&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (context != &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (threadData == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thread&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.AllocateNamedDataSlot(key);&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thread&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.SetData(threadData, context);&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; context;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Returns either Web Request scoped DataContext or a Thread scoped&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; request object if not running a Web request (ie. HttpContext.Current)&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; is not available.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="key"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="ConnectionString"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetScopedDataContext(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; key, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; connectionString)&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;//if (HttpContext.Current != null)&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;// return (TDataContext)GetWebRequestScopedDataContextInternal(typeof(TDataContext), key, connectionString);&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (TDataContext)GetThreadScopedDataContextInternal( key, connectionString);&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Returns either Web Request scoped DataContext or a Thread scoped&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; request object if not running a Web request (ie. HttpContext.Current)&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; is not available.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="key"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetScopedDataContext(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; key)&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;//if (HttpContext.Current != null)&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;// return (TDataContext)GetWebRequestScopedDataContextInternal(typeof(TDataContext), key, null);&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (TDataContext)GetThreadScopedDataContextInternal( key, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; Returns either Web Request scoped DataContext or a Thread scoped&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; request object if not running a Web request (ie. HttpContext.Current)&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt; is not available.&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;typeparam name="TDataContext"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;param name="key"&amp;gt;&amp;lt;/param&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;font color="#808080" size="2"&gt;&lt;font color="#808080" size="2"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; TDataContext GetScopedDataContext()&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;//if (HttpContext.Current != null)&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;// return (TDataContext)GetWebRequestScopedDataContextInternal(typeof(TDataContext), null, null);&lt;/font&gt;&lt;/font&gt;&lt;font size="2" /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (TDataContext)GetThreadScopedDataContextInternal( &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://www.shanghai-software.com/blog/aggbug/13.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/01/15/linq-for-sql-thread-affinity-data-context.aspx</guid>
            <pubDate>Wed, 14 Jan 2009 16:01:21 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/13.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/01/15/linq-for-sql-thread-affinity-data-context.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/13.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/13.aspx</trackback:ping>
        </item>
        <item>
            <title>OO with services </title>
            <link>http://www.shanghai-software.com/blog/archive/2009/01/14/oo-with-services.aspx</link>
            <description>&lt;p&gt;Are OO code and SOA diametrically opposed ? In a lot of ways this is true services tend to produce very anemic object models however this merely reduces reuse which is a myth in OO for the majority anyway . &lt;/p&gt;
&lt;p&gt;However services have a unique but familiar problem . The contract of the service is critical it needs to be designed for &lt;/p&gt;
&lt;p&gt; - The ease of use of the client  &lt;/p&gt;
&lt;p&gt;- For performance  ( ie chunky calls , many small calls can bring many services down to its needs) &lt;/p&gt;
&lt;p&gt;- To be upgradeable and allow backward compatibility.&lt;/p&gt;
&lt;p&gt;- Compatible with an XML schema ( eg generics and interfaces create problems) &lt;/p&gt;
&lt;p&gt;- Best to be compatible with WS standards and non &lt;a rel="" href="http://74.55.152.210/blog/WCF" title="WCF"&gt;Windows Communication Foundation&lt;/a&gt; clients ( eg nullable datetime ,  no char , long etc ) &lt;/p&gt;
&lt;p&gt;- Only sub object and collections needed for this call need to be propagated which is not all the objects and collections a object may contain.  eg Order GetOrder(..) may contain OrderItems which contain Products but no more information about the product such as supplier etc . This is best described as truncated trees. &lt;/p&gt;
&lt;p&gt;( see how to write a good contract) &lt;/p&gt;
&lt;p&gt;This is dramatically different from an OO structure  where ease of use is not high on the list else we would all be using statics , however its very similar to a relational database and its structure. &lt;/p&gt;
&lt;p&gt;Does this mean services are similar to databases ( eg Procedural Programming)  ? From the outside yes and smaller services probably should remain Procedural and non OO . (A good example is in the LINQ and services article)&lt;/p&gt;
&lt;p&gt;However larger services should retain a significant OO core with a focus on code quality , testability and maintainability however this requires a reverse ORM which maps from the messages to the internal logic.  Microsofts P&amp;amp;P Web service factory includes converterts exactly for this purposes and its a good pattern to follow. &lt;/p&gt;
&lt;p&gt;Even in small services when mapping from a  DB to messages there is a case for such a conversion layer ( and DTOs)  . Take the case of LINQ for sql if you add a member to  a DB table for some new functionality meant to be visible to a select group do you want every client to now have this information in the data sent down  ?  If custom message contracts were used only the new operation and contract used by the select group would get the new information however all the logic would be common ( just the privileged data would not be copied to contract) . If custom message contracts are not used the team would be forced to create a new schema copy of the data for the same table which would be identical  except for the one member as can be seen over time this would reduce maintainability of the service . &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://www.shanghai-software.com/blog/aggbug/12.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/01/14/oo-with-services.aspx</guid>
            <pubDate>Wed, 14 Jan 2009 15:33:15 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/12.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/01/14/oo-with-services.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/12.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/12.aspx</trackback:ping>
        </item>
        <item>
            <title>How to write a good service contracts</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/01/14/how-to-write-a-good-service-contract.aspx</link>
            <description>&lt;p&gt;... not hand craft wsdl&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Custom messages reduce churn and change in the contract&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Lets say you have this datacontract &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;[DataContract]&lt;/p&gt;
&lt;p&gt;public class WorkEntry&lt;/p&gt;
&lt;p&gt;{&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;[DataMember]&lt;/p&gt;
&lt;p&gt;public DateTime StartTime;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;[DataMember]&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;public TimeSpan Duration;&lt;/p&gt;
&lt;p&gt;[DataMember]&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;public string User;&lt;/p&gt;
&lt;p&gt;[DataMember]&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;public string CostCentre;&lt;/p&gt;
&lt;p&gt;[DataMember]&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;string Comments;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;What can go wrong here ? Using public fields is good , its tight and if you need to do custom things you can refactor it easily.  I think there is nothing really wrong here however if this is a business object also i would be concerned. &lt;br /&gt;
&lt;/p&gt;
 The big gotcha maybe DateTime  , lets say you have some other systems in your company that use Java . Now Java systems use a nullable DateTime and can send null ( and DateTime.Min can become null if emit default values is false) causing all sorts of issues . Management decides YOU must change however you have used this as a business object through your app . You can change the DateTime to DateTime? However there are a large amount of implication to your application in now having to deal with possible null values - including the SQL server and DB and hence what is a trivial change requires pretty a lot of work and risk and hence testing ( note TDD or unit testing here do not help and make it worse as the unit tests also have to change) . &lt;br /&gt;
&lt;br /&gt;
The problem here comes from using your DTO ( data transfer object eg message /DataContract) as your business object. I think this should be avoided in all cases where the service is non trivial. In Trivial services its easy enough to write a new service or make the changes and hence using the business object as the message is ok. &lt;br /&gt;
&lt;br /&gt;
Avoid .NET specifics especially&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;non int integer types &lt;/li&gt;
    &lt;li&gt;char  &lt;/li&gt;
    &lt;li&gt;generics ( not that it works) &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;serializing interfaces &lt;/li&gt;
    &lt;li&gt;inheritance&lt;/li&gt;
&lt;/ul&gt;
Ultimately messages are serialized as XML and forcing a object model onto it will always result in difficulties and leaky abstractions for the domain.  The solution is simple DONT let WCF and your communications contaminate your object models use the DTO(Data Transfer) pattern.&lt;br /&gt;
&lt;br /&gt;
see DTO pattern.&lt;br /&gt;&lt;img src="http://www.shanghai-software.com/blog/aggbug/11.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/01/14/how-to-write-a-good-service-contract.aspx</guid>
            <pubDate>Wed, 14 Jan 2009 15:10:47 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/11.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/01/14/how-to-write-a-good-service-contract.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/11.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/11.aspx</trackback:ping>
        </item>
        <item>
            <title>LINQ for SQL and reattaching objects in nTier scenarios</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/01/14/linq-for-sql-and-reattaching-objects-in-ntier-scenarios.aspx</link>
            <description>&lt;p&gt;One of the issues that keeps cropping up is LINQ for SQLs support for nTier scenarios and having to reattach the object to the DataContext. &lt;/p&gt;
&lt;p&gt;However this problem is exhibited by all ORMs in nTier scenarios ( though not in web sites) and  you basically have 2 choices &lt;/p&gt;
&lt;p&gt;- refetch the object from cache/DB and replay all changes to see what has changed then you can craft a custom Update to just change the items changed. &lt;/p&gt;
&lt;p&gt;- update all fields in the DB. &lt;/p&gt;
&lt;p&gt;While the 2nd method is easier the first is more efficient especially when you consider that it is very likely that the object is still in a cache. &lt;/p&gt;
&lt;p&gt;In both cases a row version/timestamp is normally required for concurrency .&lt;/p&gt;
&lt;p&gt; ProcessOrder ( Order order) &lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;var orderDB = ThreadDataContext.Context; //get dataContext&lt;br /&gt;
//Products is the table we draged and dropped in the dbml designer&lt;br /&gt;
var _oldOrder = (from _orders in order.Orders&lt;/font&gt;&lt;font face="Arial"&gt;           &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;select _order where _order.id =  order.id).Single();&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;//note as you have the old order and new order you can apply some logic , this is much more efficient than doing it in a db &lt;/p&gt;
&lt;p&gt;if ( &lt;font face="Arial"&gt;_oldOrder.IsFinalized())&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;   throw new InvalidOperationException("Finalized order cant be changed");&lt;/p&gt;
&lt;p&gt;if ( _OldOrder.RowVer != _order.RowVer) &lt;/p&gt;
&lt;p&gt;   throw new ConcurrencyException("Order already Changed") ;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;//update the fields&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;_oldOrder .Number = order.Number; &lt;br /&gt;
&lt;font face="Arial"&gt;_oldOrder .CustomerId = order.CustomerId; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;// etc ...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;new BLL.OrderProcessor().Process(&lt;font face="Arial"&gt;_oldOrder);  //process &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;You could use reflection to automate the copying and then the new order would just overwrite the previous order but this has 2 issues&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;It would be slow &lt;/li&gt;
    &lt;li&gt;It would allow the client  to trash the servers object by serializing  on top of it . &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is also worth noting for medium and large services you are likely to have an internal object module and code to convert from messages to internal code anyway ( see OO with services article) &lt;/p&gt;
&lt;p&gt;I think fetching the old order is good business practice anyway and stops issues like a client bug updatting a service and trashing a fulfilled order with a new one .  Fetching the old order allows you to uphold one of the SOA tennats/rules that a service should never trust a client .&lt;/p&gt;
&lt;p&gt;It is worth noting the same thing needs to be done for member objects or collections and hence its usefull to provide some simple converter classes for each type .  The result of this is that services ( that write to a DB) using an ORM tend to have an external message structure  different from the internal OO representation even when the OO model and service is quite small.  Even though this is a burden it does not introduce a lot of time or any complexity and is a good practice to follow for all but the smallest services anyway. ( Again see OO with services article) &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://www.shanghai-software.com/blog/aggbug/10.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/01/14/linq-for-sql-and-reattaching-objects-in-ntier-scenarios.aspx</guid>
            <pubDate>Wed, 14 Jan 2009 15:00:23 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/10.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/01/14/linq-for-sql-and-reattaching-objects-in-ntier-scenarios.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/10.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/10.aspx</trackback:ping>
        </item>
        <item>
            <title>Simple  services and Linq for SQL - match made in heaven</title>
            <link>http://www.shanghai-software.com/blog/archive/2009/01/14/simple-services-and-linq-for-sql-match-made.aspx</link>
            <description>&lt;p&gt;Im a pretty big fan of Linq for SQL and it works so well with services especially smaller ones ( especially when there are no updates) .&lt;/p&gt;
&lt;p&gt;The fact services are normally responsible for about 3 tables /conceptual domain classes mean you can quickly drag the 3 tables onto the designer and generate the code.   If the structure changes you just recreate the data. &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Lightweight data &lt;/li&gt;
    &lt;li&gt;Light weight service&lt;/li&gt;
    &lt;li&gt;Light weight testing &lt;/li&gt;
    &lt;li&gt;Light weight procedural code. .&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These services are quick to write and easy to maintain,&lt;/p&gt;&lt;img src="http://www.shanghai-software.com/blog/aggbug/7.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ben Kloosterman</dc:creator>
            <guid>http://www.shanghai-software.com/blog/archive/2009/01/14/simple-services-and-linq-for-sql-match-made.aspx</guid>
            <pubDate>Wed, 14 Jan 2009 12:22:29 GMT</pubDate>
            <wfw:comment>http://www.shanghai-software.com/blog/comments/7.aspx</wfw:comment>
            <comments>http://www.shanghai-software.com/blog/archive/2009/01/14/simple-services-and-linq-for-sql-match-made.aspx#feedback</comments>
            <wfw:commentRss>http://www.shanghai-software.com/blog/comments/commentRss/7.aspx</wfw:commentRss>
            <trackback:ping>http://www.shanghai-software.com/blog/services/trackbacks/7.aspx</trackback:ping>
        </item>
    </channel>
</rss>