IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace : IDataSourceKeyResolver Interface |
'Declaration
<InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)> Public Interface IDataSourceKeyResolver
'Usage
Dim instance As IDataSourceKeyResolver
[InterfaceExport(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)] public interface IDataSourceKeyResolver
If using a custom IDataSourceKeyResolver you will not need to place data source key information in your IdeaBlade Configuration file.
// Sample custom implementation of IDataSourceKeyResolver. [Serializable] public class DynamicDataSourceKeyResolver : IDataSourceKeyResolver { // This class will generate a new key when the extension of "Dynamic" is used. // All other keys are handled by the default resolver. // Note the edmKey created here is not defined in the IdeaBlade configuration file. // Also note that GetKey will be called once on both the client and the server. public IDataSourceKey GetKey(String keyName, String keyExtension, bool onServer) { // Generally no need for customization on client, so allow default resolution. if (!onServer) return null; if (keyExtension != "Dynamic") return null; // Allow default resolution of key. // We've already defined <connectionStrings> in our config file, so see what's there. var cs = IdeaBladeConfig.Instance.Configuration.ConnectionStrings.ConnectionStrings[keyName]; // Switch database server based on time of day. string connection = cs.ConnectionString; if (DateTime.UtcNow.Hour > 12) { connection = connection.Replace("Data Source=SF-Server", "Data Source=NY-Server"); } ClientEdmKey newKey = new ClientEdmKey("mynewkey", connection); return newKey; } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2