title: Linq 'Unable to process the type 'Anonymous type', because it has no known mapping to the value layer.' in MVC
body: <p>I am trying to convert a SQL Command to Linq but gets the error <em>'Unable to process the type 'Anonymous type', because it has no known mapping to the value layer.'</em></p>
  
  <p><strong>SQL Code</strong></p>
  
  <pre><code>SELECT ooe.id, parts.title, appro.totalAppro, allo.TotalAllotment, cost.total_cost, (CASE WHEN cost.total_cost IS NULL THEN (SELECT allo.TotalAllotment) ELSE (SELECT allo.TotalAllotment - cost.total_cost) END) AS unobligated 
  FROM pmTA_OoeGeneral AS ooe INNER JOIN 
       pmTA_Particulars AS parts ON ooe.particular_id = parts.id LEFT OUTER JOIN 
       pmTA_vwObligationRequestDetailsTotalCostByOoe AS cost ON ooe.id = cost.ooe_general_id 
       LEFT OUTER JOIN pmTA_vwTotalAllotmentGeneralFund AS allo ON ooe.id = allo.ooe_general_id 
       LEFT OUTER JOIN pmTA_vwTotalAppropriationGeneralFund AS appro ON ooe.id = appro.ooe_general_id 
  WHERE (ooe.year = @year) AND (ooe.project_category_id = @cat) and (ooe.type = @type) order by ooe.id
  </code></pre>
  
  <p><strong>LINQ Code</strong></p>
  
  <pre><code>    var gvStatusGenOffices = (from a in db.iBudget_OoeGeneral 
                               join b in db.iBudget_Particulars on a.ParticularID equals b.id
                               join c in obligationRequestDetailsTotalCostByOoe on a.id equals c.id
                               join d in totalAllotmentGeneralFund on a.id equals d.id
                               join e in totalAppropriationGeneralFund on a.id equals e.id
                               where a.YearID==year &amp;&amp; a.ProjectID==cat &amp;&amp; a.type==type
                               orderby a.id
                               select new
                               {
                                   id = a.id,
                                   title = b.title,
                                   appro = e.totalAppro,
                                   allo = d.totalAllo,
                                   cost = c.totalCost,
                                   unobligated = c.totalCost==null ? d.totalAllo : d.totalAllo - c.totalCost
                               }).ToList();
  </code></pre>
  
  <p><strong>db.iBudget_OoeGeneral</strong> and <strong>db.iBudget_Particulars</strong> are model class in my project </p>
  
  <p><strong>obligationRequestDetailsTotalCostByOoe</strong> , <strong>totalAllotmentGeneralFund</strong> and <strong>totalAppropriationGeneralFund</strong> are variables with list values.</p>
  
  <p>The question is what is causing this error? I tried looking the web for some answers but none was showing up. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>var obligationRequestDetailsTotalCostByOoe = (from p in db.iBudget_ObligationRequestDetails
                                   where p.ooe_general_id != null &amp;&amp; p.is_approved == 1
                                   group p by p.ooe_general_id into g
                                   select g)
                                   .AsEnumerable() 
                                   .Select(g =&gt; new {
                                       id = g.Key,
                                       totalCost = g.Sum(p =&gt; Convert.ToDouble(p.amount))
                                    }).ToList();
  </code></pre>
  
  <p>Originally, <strong>obligationRequestDetailsTotalCostByOoe</strong> , <strong>totalAllotmentGeneralFund</strong> and <strong>totalAppropriationGeneralFund</strong> were Views in SQL Server. Since I was practicing how to code Linq, I didn't create a View and just made a var with list same with the original View Code in SQL. </p>