我想分享橫跨在Silverlight多個實體相同的數據庫信息..但我想連接字符串被命名爲XYZ,讓所有人訪問,從machine.config中的連接字符串...的實體框架連接字符串
實體的元數據部分將會有所不同,因爲我沒有將實體命名爲相同的名稱。
我可以在該元數據部分放置多個實體嗎?
下面是一個例子。我想使用此連接字符串,但請注意,我把多個實體的元數據部分..
基本上,我想利用這個連接字符串
<add name="XYZ" connectionString="metadata=res://*/ModEntity.csdl|res://*/ModEntity.ssdl|res://*/ModEntity.msl;provider=System.Data.SqlClient;provider connection string="Data Source=SomeServer;Initial Catalog=SomeCatalog;Persist Security Info=True;User ID=Entity;Password=SomePassword;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
而且此連接字符串
<add name="XYZ" connectionString="metadata=res://*/Entity.csdl|res://*/Entity.ssdl|res://*/Entity.msl;provider=System.Data.SqlClient;provider connection string="Data Source=SOMESERVER;Initial Catalog=SOMECATALOG;Persist Security Info=True;User ID=Entity;Password=Entity;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
爲了使這個連接字符串
<add name="XYZ" connectionString="metadata=res://*/Entity.csdl|res://*/Entity.ssdl|res://*/Entity.msl|res://*/ModEntity.csdl|res://*/ModEntity.ssdl|res://*/ModEntity.msl;provider=System.Data.SqlClient;provider connection string="Data Source=SOMESERVER;Initial Catalog=SOMECATALOG;Persist Security Info=True;User ID=Entity;Password=SOMEPASSWORD;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
但它根本不起作用。這兩個項目都不能連接到它。
string encConnection = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
Type contextType = typeof(test_Entities);
object objContext = Activator.CreateInstance(contextType, encConnection);
return objContext as test_Entities;
請提供代碼示例;你怎麼連接?它跨域嗎? – 2011-04-25 17:47:55
相同的機器相同的域名..如果我有2個連接字符串分開它工作正常..但我會增加更多的項目和易於部署我希望他們都能夠從數據源相同的連接字符串對他們來說都是一樣的 – Rico 2011-04-25 18:18:12