<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tip 45 – How to swap EF metadata at runtime.</title><link>http://blogs.msdn.com/b/alexj/archive/2009/11/29/tip-45-how-to-swap-ef-metadata-at-runtime.aspx</link><description>Background By default the Entity Framework embeds its metadata inside your assembly as a resource. It also puts a connection string in the App or Web Config that references those resources something like this: &amp;lt;add name="BloggingEntities" connectionString</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Tip 45 – How to swap EF metadata at runtime.</title><link>http://blogs.msdn.com/b/alexj/archive/2009/11/29/tip-45-how-to-swap-ef-metadata-at-runtime.aspx#9929905</link><pubDate>Sun, 29 Nov 2009 21:56:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9929905</guid><dc:creator>Ann</dc:creator><description>&lt;p&gt;Clarifying my question..&lt;/p&gt;
&lt;p&gt;The production and test are on the same database system one is called &amp;nbsp;hardtest and the other hardprod. i.e &amp;nbsp;databases or schemas in the same database system/machine&lt;/p&gt;
&lt;p&gt;My question was in regard to designing using hardtest but then at runtime changing to use hardprod. Assuming the both hardtest and hardprod are the same structure I should be able to do this without issue.&lt;/p&gt;
&lt;p&gt;The issue issue I'm having is the the SQL EF is producing contains the database/schema name of the design time database. ie the sql looks like &amp;quot;Select * from &amp;nbsp;hardtest.task&amp;quot; instead of &amp;nbsp;&amp;quot;Select * from hardprod.task&amp;quot;&lt;/p&gt;
&lt;p&gt;The reason I think this is happening is that EF is storing the schema name in the SSDL EntitySet as stated above.&lt;/p&gt;
&lt;p&gt;If I manual edit the SSDL by deleting the Schema attribute in all the EntitySets them I get generic SQL that works ie SQL without any Schema defined &amp;quot;Select * from task&amp;quot;&lt;/p&gt;
&lt;p&gt;The problem with doing this is that when I try to update the EF model again it adds back all the EF entities (because I remove the Schema attribute from the SSDL it thinks everything is new and adds it to the model for a 2nd time)&lt;/p&gt;
&lt;p&gt;The solution you proposed in your blog post is about changing the SSDL and other files if the database design is different. But what is they are the same and I just want the generic SQL to not include the schemas.&lt;/p&gt;
&lt;p&gt;One thing is note is that changing the connection string does make EF hit the correct database/schema.. but the SQL being executed at this time contains the design time database name or schema.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9929905" width="1" height="1"&gt;</description></item><item><title>re: Tip 45 – How to swap EF metadata at runtime.</title><link>http://blogs.msdn.com/b/alexj/archive/2009/11/29/tip-45-how-to-swap-ef-metadata-at-runtime.aspx#9929895</link><pubDate>Sun, 29 Nov 2009 20:49:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9929895</guid><dc:creator>Alex D James</dc:creator><description>&lt;p&gt;@Anon (?)&lt;/p&gt;
&lt;p&gt;the Schema is not the database name, it is the schema, usually it is something like 'dbo'.&lt;/p&gt;
&lt;p&gt;Both your production and development databases can have the same schema.&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9929895" width="1" height="1"&gt;</description></item><item><title>re: Tip 45 – How to swap EF metadata at runtime.</title><link>http://blogs.msdn.com/b/alexj/archive/2009/11/29/tip-45-how-to-swap-ef-metadata-at-runtime.aspx#9929891</link><pubDate>Sun, 29 Nov 2009 20:27:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9929891</guid><dc:creator>Anon</dc:creator><description>&lt;p&gt;Hi Alex,&lt;/p&gt;
&lt;p&gt;A related issue I'm having is changing the database at runtime.&lt;/p&gt;
&lt;p&gt;I think the root cause is the in the SSDL entitysets are being created with the Schema attribute&lt;/p&gt;
&lt;p&gt;ie&lt;/p&gt;
&lt;p&gt; &amp;lt;EntitySet Name=&amp;quot;task&amp;quot; EntityType=&amp;quot;hardModel.Store.task&amp;quot; store:Type=&amp;quot;Tables&amp;quot; Schema=&amp;quot;harder&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;The result is that the database name is appearing the the final slq being executed, the database name being the design time database.&lt;/p&gt;
&lt;p&gt;Is there a workaround to prevent this from happening? I do not mind being limits to just one database.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9929891" width="1" height="1"&gt;</description></item></channel></rss>