Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of <code>select new</code> do <code>select p</code>. Currently you are selecting anonymous object and you can't convert it to <code>System.Linq.IQueryable CustomMethod.Order_Detail</code> </p> <p>You can't project to <code>Order_Detail</code> since it appears to be a class of framework. Since you are doing calculation in your anonymous object, You can either return <code>IQueryable&lt;Order_Detail&gt;</code> by <code>select p</code> and do the calculation later on LINQ to object, or you may create a new class and project to that. If you end up creating a new class then you should modify your signature as per class name. </p> <pre><code>public IQueryable&lt;Order_Detail&gt; getByYear(int year) { var dc = new NorthwindBigEntities(); var query = from p in dc.Order_Details where p.Order.OrderDate != null &amp;&amp; p.Order.OrderDate.Value.Year == year select p; return query; } </code></pre> <p>If you create a new class like:</p> <pre><code>public class MyClass { public string Product {get;set;} public double TotalSales {get;set;} } </code></pre> <p>Then you can do </p> <pre><code>public IQueryable&lt;MyClass&gt; getByYear(int year) { var dc = new NorthwindBigEntities(); var query = from p in dc.Order_Details where p.Order.OrderDate != null &amp;&amp; p.Order.OrderDate.Value.Year == year select new MyClass { TotalSales = p.UnitPrice * p.Quantity, Product = p.Product.ProductName }; return query; } </code></pre> <p>Considering <strong>its a service returning data, its better if you create your own class</strong> and return only the required properties. You should also see <a href="https://stackoverflow.com/questions/460831/linq-to-sql-return-from-function-as-iqueryablet">this question</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload