Visual Basic (Declaration) | |
---|---|
Public Function New( _ Optional ByVal shouldConnect As Boolean, _ Optional ByVal dataSourceExtension As String, _ Optional ByVal entityServiceOption As EntityServiceOption, _ Optional ByVal compositionContextName As String _ ) |
Visual Basic (Usage) | ![]() |
---|---|
Dim shouldConnect As Boolean Dim dataSourceExtension As String Dim entityServiceOption As EntityServiceOption Dim compositionContextName As String Dim instance As New EntityManager(shouldConnect, dataSourceExtension, entityServiceOption, compositionContextName) |
C# | |
---|---|
public EntityManager( bool shouldConnect, string dataSourceExtension, EntityServiceOption entityServiceOption, string compositionContextName ) |
C++/CLI | |
---|---|
public: EntityManager( bool shouldConnect, String^ dataSourceExtension, EntityServiceOption entityServiceOption, String^ compositionContextName ) |
Parameters
- shouldConnect
- True if a connection to the EntityServer should be made.
- dataSourceExtension
- The DataSourceKey extension to search for in IdeaBlade configuration file.
- entityServiceOption
- Determines whether to use local or distributed data sources.
- compositionContextName
- Optional name of the CompositionContext to use for MEF composition.
Exception | Description |
---|---|
IdeaBlade.Core.IdeaBladeException | Thrown for miscellaneous initialization failures |
IdeaBlade.EntityModel.EntityServerException | Thrown for connection failures |
System.ArgumentException | Thrown in a Silverlight application when BOS is not specified |
C# | ![]() |
---|---|
private bool Initialize() { string runTimeEnv; #if TEST runTimeEnv = "Test"; #else runTimeEnv = "Prod"; #endif // Initialize an EntityManager for the given data source extension, and set up an error handler. IdeaBladeTest1Manager mgr = new IdeaBladeTest1Manager(false, runTimeEnv); mgr.EntityServerError += EntityServerErrorHandler; // Explicitly connect to the BOS now. // Note that no data source connection is made until entities are accessed. try { mgr.Connect(); } catch (EntityServerException ese) { MessageBox.Show(ese.Message, "EntityServerException"); } catch (Exception e) { MessageBox.Show(e.Message, "Exception"); } return mgr.IsConnected; } private void EntityServerErrorHandler(object pSender, EntityServerErrorEventArgs e) { // Always a good idea to log all exception info. Exception ex = e.Exception; while (ex != null) { TraceFns.WriteLine(ex.ToString()); ex = ex.InnerException; } MessageBox.Show("Trying to handle error"); // Leave e.Handled = false if the Error should be thrown back to the calling code e.Handled = true; // exception will not be thrown } |
You can also choose whether a connection to the IdeaBlade.EntityModel.Server.EntityServer should be made now. If shouldConnect is true
you will not be able to catch any IdeaBlade.EntityModel.EntityServerException thrown due to connection problems in an EntityServerError handler since the handler will not yet be set; you should instead wrap the call in a try/catch. If shouldConnect is false
then you will need to call the Connect method when you are ready to begin communicating with the EntityServer.
Use the entityServiceOption to explicitly specify whether you will be using local or distributed data sources. By default the ObjectServer element in the IdeaBlade configuration file determines this, but if you need to use both local and distributed data sources within the same application you'll use the EntityServiceOption to indicate what the EntityManager will use. See the "Access Both Local and Remote Data Sources In the Same N-tier Application" topic in the DevForce Resource Center for more information.
You can also provide the name of the CompositionContext to be used to compose parts for runtime extensibility. By default if you don't provide a name the "default" context is used. See the CompositionContext for more information and sample usage.
No connection to data sources is made during EntityManager initialization.
An EntityManagerCreated event is fired upon creation.
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