Linq To Sql return from function as IQueryable

前端 未结 4 1881
梦如初夏
梦如初夏 2021-01-13 04:54

Ok, I have managed to get the following working

public IQueryable getTicketInformation(int ticketID)
{
    var ticketDetails = from tickets in _context.ticke         


        
4条回答
  •  迷失自我
    2021-01-13 05:42

    As Marc stated you're not constructing instances of myObject when your query is run. But additionally you don't need to cast it to an IQueryable, a LINQ select statment will return an IQueryable unless explicity cast to an IEnumerable.

    Also, be careful that your DataContext hasn't been disposed of before you try and access the data being returned. But I noticed your context is not constructed in the method, be careful that you're not maintaining a DataContext for too long, it's a unit-of-work object and not meant to be kept open for long periods of time.

提交回复
热议问题