# C1.Data.Entities.EntityClientCache.RegisterContext

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Data_Entities_EntityClientCache_RegisterContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext*">RegisterContext Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Data_Entities_EntityClientCache_RegisterContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext*"></a>
<h4 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_Core_Objects_ObjectContext_System_Type_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext(System.Data.Entity.Core.Objects.ObjectContext,System.Type)">RegisterContext(ObjectContext, Type)</h4>
<div class="markdown level1 summary"><p>Registers an <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> as a default for C1DataSource controls for a given <code class="paramref">contextType</code>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IDisposable RegisterContext(ObjectContext context, Type contextType)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function RegisterContext(context As ObjectContext, contextType As Type) As IDisposable</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">ObjectContext</span></td>
      <td><span class="parametername">context</span></td>
      <td><p>An <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> to set as default.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a></td>
      <td><span class="parametername">contextType</span></td>
      <td><p>The type (derived from <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a>) to register the <code class="paramref">context</code> for.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></td>
      <td><p>An <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a> to unregister the <code class="paramref">context</code>.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_Core_Objects_ObjectContext_System_Type__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Use this method when you need to customize the default <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> used in C1DataSource controls.
Register a custom <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> on startup before any C1DataSource instances are created.</p>
</div>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidoperationexception">InvalidOperationException</a></td>
      <td><p>Another context is already registered for the given <code class="paramref">contextType</code>.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_Core_Objects_ObjectContext_System_Type__seealso">See Also</h5>
<div class="seealso">
    <div><a class="xref" href="C1.Data.Entities.EntityClientCache.GetDefault.html#C1_Data_Entities_EntityClientCache_GetDefault_System_Type_">GetDefault</a>(<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a>)</div>
</div>


<a id="C1_Data_Entities_EntityClientCache_RegisterContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext*"></a>
<h4 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_Core_Objects_ObjectContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext(System.Data.Entity.Core.Objects.ObjectContext)">RegisterContext(ObjectContext)</h4>
<div class="markdown level1 summary"><p>Registers an <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> as a default for C1DataSource controls.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IDisposable RegisterContext(ObjectContext context)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function RegisterContext(context As ObjectContext) As IDisposable</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">ObjectContext</span></td>
      <td><span class="parametername">context</span></td>
      <td><p>An <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> to set as default.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></td>
      <td><p>An <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a> to unregister the <code class="paramref">context</code>.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_Core_Objects_ObjectContext__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Use this method when you need to customize the default <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> used in C1DataSource controls.
Register a custom <a class="xref" href="C1.Data.Entities.EntityClientCache.ObjectContext.html#C1_Data_Entities_EntityClientCache_ObjectContext">ObjectContext</a> on startup before any C1DataSource instances are created.</p>
</div>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidoperationexception">InvalidOperationException</a></td>
      <td><p>Another context is already registered.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_Core_Objects_ObjectContext__seealso">See Also</h5>
<div class="seealso">
    <div><a class="xref" href="C1.Data.Entities.EntityClientCache.GetDefault.html#C1_Data_Entities_EntityClientCache_GetDefault_System_Type_">GetDefault</a>(<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a>)</div>
</div>


<a id="C1_Data_Entities_EntityClientCache_RegisterContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext*"></a>
<h4 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_DbContext_System_Type_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext(System.Data.Entity.DbContext,System.Type)">RegisterContext(DbContext, Type)</h4>
<div class="markdown level1 summary"><p>Registers an <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> as a default for C1DataSource controls for a given <code class="paramref">contextType</code>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IDisposable RegisterContext(DbContext context, Type contextType)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function RegisterContext(context As DbContext, contextType As Type) As IDisposable</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">DbContext</span></td>
      <td><span class="parametername">context</span></td>
      <td><p>An <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> to set as default.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a></td>
      <td><span class="parametername">contextType</span></td>
      <td><p>The type (derived from <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a>) to register the <code class="paramref">context</code> for.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></td>
      <td><p>An <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a> to unregister the <code class="paramref">context</code>.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_DbContext_System_Type__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Use this method when you need to customize the default <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> used in C1DataSource controls.
Register a custom <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> on startup before any C1DataSource instances are created.</p>
</div>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidoperationexception">InvalidOperationException</a></td>
      <td><p>Another context is already registered for the given <code class="paramref">contextType</code>.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_DbContext_System_Type__seealso">See Also</h5>
<div class="seealso">
    <div><a class="xref" href="C1.Data.Entities.EntityClientCache.GetDefault.html#C1_Data_Entities_EntityClientCache_GetDefault_System_Type_">GetDefault</a>(<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a>)</div>
</div>


<a id="C1_Data_Entities_EntityClientCache_RegisterContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext*"></a>
<h4 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_DbContext_" data-uid="C1.Data.Entities.EntityClientCache.RegisterContext(System.Data.Entity.DbContext)">RegisterContext(DbContext)</h4>
<div class="markdown level1 summary"><p>Registers an <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> as a default for C1DataSource controls.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static IDisposable RegisterContext(DbContext context)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function RegisterContext(context As DbContext) As IDisposable</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">DbContext</span></td>
      <td><span class="parametername">context</span></td>
      <td><p>An <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> to set as default.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></td>
      <td><p>An <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a> to unregister the <code class="paramref">context</code>.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_DbContext__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Use this method when you need to customize the default <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> used in C1DataSource controls.
Register a custom <a class="xref" href="C1.Data.Entities.EntityClientCache.DbContext.html#C1_Data_Entities_EntityClientCache_DbContext">DbContext</a> on startup before any C1DataSource instances are created.</p>
</div>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidoperationexception">InvalidOperationException</a></td>
      <td><p>Another context is already registered.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Data_Entities_EntityClientCache_RegisterContext_System_Data_Entity_DbContext__seealso">See Also</h5>
<div class="seealso">
    <div><a class="xref" href="C1.Data.Entities.EntityClientCache.GetDefault.html#C1_Data_Entities_EntityClientCache_GetDefault_System_Type_">GetDefault</a>(<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.type">Type</a>)</div>
</div>
</div>
