IdeaBlade DevForce 2010 Help Reference
IDataSourceKeyResolver Interface
Members  Example  See Also  Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace : IDataSourceKeyResolver Interface



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 
Visual Basic (Usage)Copy Code
Dim instance As 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

The DefaultDataSourceKeyResolver is used by default to determine the key and connection information to be used when accessing a data source. To override this behavior implement a custom IDataSourceKeyResolver. If a custom IDataSourceKeyResolver is found, a single instance of the class will be created for the EntityManager and called for all data source key resolution.

If using a custom IDataSourceKeyResolver you will not need to place data source key information in your IdeaBlade Configuration file.

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

© 2013 All Rights Reserved.