<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Creating LightSpeed Context?</title> <atom:link href="http://www.mindscape.co.nz/blog/index.php/2009/01/12/creating-lightspeed-context/feed/" rel="self" type="application/rss+xml" /><link>http://www.mindscape.co.nz/blog/index.php/2009/01/12/creating-lightspeed-context/</link> <description>The official blog of Mindscape</description> <lastBuildDate>Sun, 05 Sep 2010 10:07:39 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>By: Ivan Towlson</title><link>http://www.mindscape.co.nz/blog/index.php/2009/01/12/creating-lightspeed-context/comment-page-1/#comment-28593</link> <dc:creator>Ivan Towlson</dc:creator> <pubDate>Sun, 25 Jan 2009 20:26:43 +0000</pubDate> <guid
isPermaLink="false">http://www.mindscape.co.nz/blog/?p=379#comment-28593</guid> <description>You can use the same LightSpeedContext for multiple .lsmodel files.  A LightSpeedContext is basically a place to store connection strings and other configuration settings: it doesn&#039;t care about the types of entity.However, if you are using LINQ, the way the designer generates strong-typed unit of work classes mitigates against this.  If you have three .lsmodel files, A, B and C, then the designer will create three LINQ UOW types: AUnitOfWork, BUnitOfWork and CUnitOfWork, each with helper properties specific to its own .lsmodel.  The way you would usually get an AUnitOfWork is to create a LightSpeedContext&lt;AUnitOfWork&gt; and call context.CreateUnitOfWork().  So in this case you *would* end up needing three contexts, one for each UOW type.  But if you do this you also need to be careful that your business transactions don&#039;t span .lsmodel files, because if you have an AUnitOfWork and a BUnitOfWork running simultaneously, they don&#039;t know about each other.  This shouldn&#039;t be an issue because you can&#039;t easily create relationships which span .lsmodel files, but just in case!  (An alternative in this case is to create a &quot;unified&quot; LINQ helper class, e.g. ABCUnitOfWork, by hand.)Don&#039;t worry about the memory cost of creating multiple LightSpeedContexts: it&#039;s insignificant.No, you can&#039;t &quot;connect&quot; two databases using LightSpeed, but you may be able to do so using features of the underlying database, e.g. if most of your entities are in database A but some are in database B, you might be able to create a view in database A which surfaces the entities from database B.  Check your database documentation.  You *can* have entities from different databases loaded simultaneously, but they will be in different units of work and will be saved separately; also you must be careful not to establish EntityHolder or EntityCollection relationships between them or LightSpeed may try to gather them into the same UOW.</description> <content:encoded><![CDATA[<p>You can use the same LightSpeedContext for multiple .lsmodel files.  A LightSpeedContext is basically a place to store connection strings and other configuration settings: it doesn&#8217;t care about the types of entity.</p><p>However, if you are using LINQ, the way the designer generates strong-typed unit of work classes mitigates against this.  If you have three .lsmodel files, A, B and C, then the designer will create three LINQ UOW types: AUnitOfWork, BUnitOfWork and CUnitOfWork, each with helper properties specific to its own .lsmodel.  The way you would usually get an AUnitOfWork is to create a LightSpeedContext<aunitofwork> and call context.CreateUnitOfWork().  So in this case you *would* end up needing three contexts, one for each UOW type.  But if you do this you also need to be careful that your business transactions don&#8217;t span .lsmodel files, because if you have an AUnitOfWork and a BUnitOfWork running simultaneously, they don&#8217;t know about each other.  This shouldn&#8217;t be an issue because you can&#8217;t easily create relationships which span .lsmodel files, but just in case!  (An alternative in this case is to create a &#8220;unified&#8221; LINQ helper class, e.g. ABCUnitOfWork, by hand.)</p><p>Don&#8217;t worry about the memory cost of creating multiple LightSpeedContexts: it&#8217;s insignificant.</p><p>No, you can&#8217;t &#8220;connect&#8221; two databases using LightSpeed, but you may be able to do so using features of the underlying database, e.g. if most of your entities are in database A but some are in database B, you might be able to create a view in database A which surfaces the entities from database B.  Check your database documentation.  You *can* have entities from different databases loaded simultaneously, but they will be in different units of work and will be saved separately; also you must be careful not to establish EntityHolder or EntityCollection relationships between them or LightSpeed may try to gather them into the same UOW.</aunitofwork></p> ]]></content:encoded> </item> <item><title>By: nefajciar</title><link>http://www.mindscape.co.nz/blog/index.php/2009/01/12/creating-lightspeed-context/comment-page-1/#comment-28559</link> <dc:creator>nefajciar</dc:creator> <pubDate>Sat, 24 Jan 2009 18:11:11 +0000</pubDate> <guid
isPermaLink="false">http://www.mindscape.co.nz/blog/?p=379#comment-28559</guid> <description>in the video (and article) you&#039;ve mentioned that usually you are working with one database thus only 1 context is needed...If I am working with one database, that is ok, but what if I want to have 3 .lsmodel files, each with different entities/tables so my .lsmodel file/schema won&#039;t be too big/complicated.Is it better to &quot;separate database&quot; into contexts or is it better (more efficient) to really have just one context of ALL MY TABLES in the database? I don&#039;t know what is more memory intensive, but thinking about that you aren&#039;t disposing context the first option is probably right one.I thought that when I am working with just small portion of my database at one time, there is no need for the .lsmodel to be so big.How about when I am using 2 databases, is there a chance to &quot;connect&quot; them? Having a membership database for example...</description> <content:encoded><![CDATA[<p>in the video (and article) you&#8217;ve mentioned that usually you are working with one database thus only 1 context is needed&#8230;</p><p>If I am working with one database, that is ok, but what if I want to have 3 .lsmodel files, each with different entities/tables so my .lsmodel file/schema won&#8217;t be too big/complicated.</p><p>Is it better to &#8220;separate database&#8221; into contexts or is it better (more efficient) to really have just one context of ALL MY TABLES in the database? I don&#8217;t know what is more memory intensive, but thinking about that you aren&#8217;t disposing context the first option is probably right one.</p><p>I thought that when I am working with just small portion of my database at one time, there is no need for the .lsmodel to be so big.</p><p>How about when I am using 2 databases, is there a chance to &#8220;connect&#8221; them? Having a membership database for example&#8230;</p> ]]></content:encoded> </item> <item><title>By: Ivan Towlson</title><link>http://www.mindscape.co.nz/blog/index.php/2009/01/12/creating-lightspeed-context/comment-page-1/#comment-28511</link> <dc:creator>Ivan Towlson</dc:creator> <pubDate>Fri, 23 Jan 2009 01:46:05 +0000</pubDate> <guid
isPermaLink="false">http://www.mindscape.co.nz/blog/?p=379#comment-28511</guid> <description>You have a variety of options here (not necessarily a good thing I know):1. Create multiple entries in the lightSpeedContexts configuration section, each referring to a different connection string.  E.g.:&lt;lightSpeedContexts&gt;
&lt;add name=&quot;Dev&quot; connectionStringName=&quot;Dev&quot; ... /&gt;
&lt;add name=&quot;Live&quot; connectionStringName=&quot;Live&quot; ... /&gt;
&lt;/lightSpeedContexts&gt;Then use these by passing in the appropriate string to the LightSpeedContext constructor:string configName = GetConfigNameFromSomewhere();
_context = new LightSpeedContext(configName);The benefit of this is that it results in simpler, clearer code, and that it gives you full flexibility in setting up different configurations (e.g. if you want a configuration where caching is turned off, or your app is meant to run on either SQL Server or Oracle, so you want test configs for each of them).  The downside is that in typical situations, where only the connection string is varying, there will likely be a lot of duplication between the &quot;Dev&quot;, &quot;Test&quot;, &quot;Live&quot; etc. config file entries.  Also, if you have to include a password in the connection string (e.g. you are using something like Oracle which doesn&#039;t have an &quot;integrated security&quot; option), you may not want the production password out there in a config file that any dev can look at (encrypted connection strings might help here but I suspect the unencrypted string would still be visible in the debugger).2. Have a single &lt;lightSpeedContext&gt; configuration file entry, and edit the connectionStringName setting when you copy the app.exe.config / web.config into another environment.  Since you are presumably having to edit some config setting to signal which environment you&#039;re in anyway, this shouldn&#039;t be a major burden.3. Have a single &lt;lightSpeedContext&gt; configuration file entry, and initialise LightSpeedContext.ConnectionString explicitly in code from the &lt;connectionStrings&gt; section:&lt;lightSpeedContexts&gt;
&lt;add name=&quot;default&quot; ... /&gt; &lt;!-- no connectionStringName --&gt;
&lt;/lightSpeedContexts&gt;string connStrName = GetConnStrNameFromSomewhere();
_context = new LightSpeedContext(&quot;default&quot;);
_context.ConnectionString = ConfigurationManager.ConnectionStrings[connStrName];The benefit of this is that you need specify model-level parameters only once.  The downside is that you need to remember to explicitly load configuration-dependent parameters from code.My feeling is that the first option is probably the simplest but you would have to consider the security issues.Notice that in all three cases you should be using the last technique JD mentioned, i.e. new LightSpeedContext(configName), rather than copying properties one by one from LightSpeedContext.Default.  LightSpeedContext.Default is essentially a wrapper for new LightSpeedContext(&quot;default&quot;): use it if you have only one config (or are using option 3) and want to save a few characters of typing.  You should never use the technique of copying properties one by one from LightSpeedContext.Default, because if we add a new property, and you decide to make use of that property, you&#039;ll have to remember to update your copying code as well as adding it to your config, and that&#039;s twice the work!Regarding how to pass the context name into a Repository class, you could either:1. Externalise this: have your app code create the LightSpeedContext, and pass the LightSpeedContext object into the Repository class; or2. Pass the config entry name into the Repository class and have it use that when creating the LightSpeedContext.Hope this helps!</description> <content:encoded><![CDATA[<p>You have a variety of options here (not necessarily a good thing I know):</p><p>1. Create multiple entries in the lightSpeedContexts configuration section, each referring to a different connection string.  E.g.:</p> <lightspeedcontexts> <add
name="Dev" connectionStringName="Dev" ... /><br
/> <add
name="Live" connectionStringName="Live" ... /> </lightspeedcontexts><p>Then use these by passing in the appropriate string to the LightSpeedContext constructor:</p><p>string configName = GetConfigNameFromSomewhere();<br
/> _context = new LightSpeedContext(configName);</p><p>The benefit of this is that it results in simpler, clearer code, and that it gives you full flexibility in setting up different configurations (e.g. if you want a configuration where caching is turned off, or your app is meant to run on either SQL Server or Oracle, so you want test configs for each of them).  The downside is that in typical situations, where only the connection string is varying, there will likely be a lot of duplication between the &#8220;Dev&#8221;, &#8220;Test&#8221;, &#8220;Live&#8221; etc. config file entries.  Also, if you have to include a password in the connection string (e.g. you are using something like Oracle which doesn&#8217;t have an &#8220;integrated security&#8221; option), you may not want the production password out there in a config file that any dev can look at (encrypted connection strings might help here but I suspect the unencrypted string would still be visible in the debugger).</p><p>2. Have a single <lightspeedcontext> configuration file entry, and edit the connectionStringName setting when you copy the app.exe.config / web.config into another environment.  Since you are presumably having to edit some config setting to signal which environment you&#8217;re in anyway, this shouldn&#8217;t be a major burden.</p><p>3. Have a single </lightspeedcontext> <lightspeedcontext> configuration file entry, and initialise LightSpeedContext.ConnectionString explicitly in code from the <connectionstrings> section:</p> <lightspeedcontexts> <add
name="default" ... /> </lightspeedcontexts><p>string connStrName = GetConnStrNameFromSomewhere();<br
/> _context = new LightSpeedContext(&#8220;default&#8221;);<br
/> _context.ConnectionString = ConfigurationManager.ConnectionStrings[connStrName];</p><p>The benefit of this is that you need specify model-level parameters only once.  The downside is that you need to remember to explicitly load configuration-dependent parameters from code.</p><p>My feeling is that the first option is probably the simplest but you would have to consider the security issues.</p><p>Notice that in all three cases you should be using the last technique JD mentioned, i.e. new LightSpeedContext(configName), rather than copying properties one by one from LightSpeedContext.Default.  LightSpeedContext.Default is essentially a wrapper for new LightSpeedContext(&#8220;default&#8221;): use it if you have only one config (or are using option 3) and want to save a few characters of typing.  You should never use the technique of copying properties one by one from LightSpeedContext.Default, because if we add a new property, and you decide to make use of that property, you&#8217;ll have to remember to update your copying code as well as adding it to your config, and that&#8217;s twice the work!</p><p>Regarding how to pass the context name into a Repository class, you could either:</p><p>1. Externalise this: have your app code create the LightSpeedContext, and pass the LightSpeedContext object into the Repository class; or</p><p>2. Pass the config entry name into the Repository class and have it use that when creating the LightSpeedContext.</p><p>Hope this helps!</connectionstrings></lightspeedcontext> ]]></content:encoded> </item> <item><title>By: Paul</title><link>http://www.mindscape.co.nz/blog/index.php/2009/01/12/creating-lightspeed-context/comment-page-1/#comment-28510</link> <dc:creator>Paul</dc:creator> <pubDate>Fri, 23 Jan 2009 00:54:15 +0000</pubDate> <guid
isPermaLink="false">http://www.mindscape.co.nz/blog/?p=379#comment-28510</guid> <description>That&#039;s made things a lot clearer for me thanks.
One question - how would you go about passing in the context name to your Repository class, assuming that you had set up say, &quot;Dev&quot; and &quot;Live&quot; connection strings in your App.config, which in turn were linked to LightSpeedContexts of &quot;default&quot; and &quot;other&quot; ?
Or alternatively, if you just had &quot;default&quot; and wanted to change the connectionStringName at runtime by passing in either &quot;Dev&quot; or &quot;Live&quot; ?
As I&#039;m a bit new to C# I&#039;m struggling with the syntax of passing in a parameter to the Context property...</description> <content:encoded><![CDATA[<p>That&#8217;s made things a lot clearer for me thanks.<br
/> One question &#8211; how would you go about passing in the context name to your Repository class, assuming that you had set up say, &#8220;Dev&#8221; and &#8220;Live&#8221; connection strings in your App.config, which in turn were linked to LightSpeedContexts of &#8220;default&#8221; and &#8220;other&#8221; ?<br
/> Or alternatively, if you just had &#8220;default&#8221; and wanted to change the connectionStringName at runtime by passing in either &#8220;Dev&#8221; or &#8220;Live&#8221; ?<br
/> As I&#8217;m a bit new to C# I&#8217;m struggling with the syntax of passing in a parameter to the Context property&#8230;</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (request URI is rejected)

Served from: www.mindscape.co.nz @ 2010-09-08 01:57:39 -->