Search code examples
c#linqado.net-entity-data-model

Best practice in returning select query in linq


I'm a little confused on what among this list below what to use in returning select in linq.

1.IEnumerable 2.List 3.ObjectQuery 4. ConvertLinqtoDataTable

Which do you prefer?

Currently we are used objectquery in returning records.

  public ObjectQuery StationSelectByStationId(int stationid)
    {
        var query = from station in _iiqrEntities.Station
                    where station.StationId == stationid
                    select station;

        return query as ObjectQuery;
    }

I will used your recommendation so that we will standardize our code. Please reference your answer based on my code above.

Thanks in Regards


Solution

  • You should return an IQueryable<T>.
    This allows consumers to add projections to the SQL query without coupling your interface to EF.