Interface used to resolve the data source key which will be used to connect to a data source.
Syntax
Visual Basic (Declaration) | |
---|
<InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)>
Public Interface IDataSourceKeyResolver |
C# | |
---|
[InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)]
public interface IDataSourceKeyResolver |
C++/CLI | |
---|
[InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)]
public interface class IDataSourceKeyResolver |
Example
C# | Copy Code |
---|
// 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;
}
} |
Remarks
Requirements
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family
See Also