Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq To Sql return from function as IQueryable<T>
    text
    copied!<p>Ok, I have managed to get the following working</p> <pre><code>public IQueryable getTicketInformation(int ticketID) { var ticketDetails = from tickets in _context.tickets join file in _context.file_objects on tickets.ticket_id equals file.source_id where tickets.ticket_id == ticketID select new { tickets.ticket_id, tickets.title, tickets.care_of_email, file.filename }; return ticketDetails.AsQueryable(); } </code></pre> <p>I went ahead and created my own class (myObject) containing the primitives ticket_id, title, care_of_email and filename. Which are the items I am returning in my linq statement.</p> <p>I modified my statement to be</p> <pre><code>public IQueryable&lt;myObject&gt; getTicketInformation(int ticketID) { var ticketDetails = from tickets in _context.tickets join file in _context.file_objects on tickets.ticket_id equals file.source_id where tickets.ticket_id == ticketID select new { tickets.ticket_id, tickets.title, tickets.care_of_email, file.filename }; return ticketDetails.AsQueryable()&lt;myObject&gt;; } </code></pre> <p>thinking that this would make it type safe with generics, but I get the error "Cannot convert method group 'AsQueryable' to non-delegate type 'System.Linq.IQueryable'. Did you intend to invoke the method?"</p> <p>Is what I am trying to do even possible?</p> <p>Does the myObject class need to implement IEnumerable or IQueryable?</p> <p>Or is it best to construct the object MyObject from the linq resultset and then just return from the function the object MyObject</p> <pre><code>public myObject getTicketInformation(int ticketID) { ....linq statement.... myObject o = null; foreach (obj in linqstatemt) { o = new myObject(); o.ticket_id = obj.ticket_id ....... } return o; } </code></pre>
 

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