title: Extending System.Data.Linq.DataContext
body: <p>I have a class reflecting my dbml file which extends DataContext, but for some strange reason it's telling me</p>
  
  <blockquote>
    <p>System.Data.Linq.DataContext' does not contain a constructor that takes '0' arguments"</p>
  </blockquote>
  
  <p>I've followed various tutorials on this and haven't encountered this problem, and VS doesn't seem to able to fix it.</p>
  
  <p>Here's my implementation</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.Linq;
  using System.Data.Linq.Mapping;
  using System.Reflection;
  using System.Text;
  using IntranetMvcAreas.Areas.Accounts.Models;
  
  namespace IntranetMvcAreas
  {
    partial class ContractsControlDataContext : DataContext
    {
      [FunctionAttribute(Name="dbo.procCC_Contract_Select")]
      [ResultType(typeof(Contract))]
      [ResultType(typeof(ContractCostCentre))]
      [ResultType(typeof(tblCC_Contract_Data_Terminal))]
      [ResultType(typeof(tblCC_CDT_Data_Service))]
      [ResultType(typeof(tblCC_Data_Service))]
      public IMultipleResults procCC_Contract_Select(
          [Parameter(Name = "ContractID", DbType = "Int")] System.Nullable&lt;int&gt; ContractID,
          [Parameter(Name = "ResponsibilityKey", DbType = "Int")] System.Nullable&lt;int&gt; ResponsibilityKey,
          [Parameter(Name = "ExpenseType", DbType = "Char")] System.Nullable&lt;char&gt; ExpenseType,
          [Parameter(Name = "SupplierID", DbType = "Int")] System.Nullable&lt;int&gt; SupplierID)
      {
  
        IExecuteResult result = this.ExecuteMethodCall(this, (MethodInfo)(MethodInfo.GetCurrentMethod()), ContractID, ResponsibilityKey, ExpenseType, SupplierID);
        return (IMultipleResults)result.ReturnValue;
      }
    }
  }
  </code></pre>
  
  <p>And it's <code>ContractsControlDataContext</code> that's pointed at as the problem</p>
  
  <p>(btw, this has no relation to a very recent post I made, it's just I'm working on the same thing)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It's probably worth clarifying this, so please read very carefully.</p>
  
  <p>If you <em>do not</em> extend DataContext in the partial class, then <code>ExecuteMethodCall</code> isn't accessible.</p>
  
  <blockquote>
    <p>'Intranet.ContractsControlDataContext' does not contain a definition for 'ExecuteMethodCall' and no extension method 'ExecuteMethodCall' accepting a first argument of type 'Intranet.ContractsControlDataContext' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>Maybe I'm missing something incredibly stupid?</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>I think perhaps Visual Studio struggled here, but I've relied entirely on auto-generated code.  When right clicking on the database modeling language design view and hitting "View Code" it automagically creates a partial class for you within a specific namespace, <em>however</em>, this namespace was wrong.  If someone could clarify this for me I would be most appreciative.</p>
  
  <p>The .designer.cs file sits in <code>namespace Intranet.Areas.Accounts.Models</code>, however the .cs file (partial class generated <strong>for</strong> the .designer.cs file <strong>by</strong> Visual Studio) was in <code>namespace Intranet</code>.  Easy to spot for someone more experienced in this area than me.</p>
  
  <p>The real problem now is, who's answer do I mark as correct? Because many of you contributed to finding this issue.</p>