This (northwind in LINQPad, adapter)
(from p in Product
select new {p}).OrderBy(x=>x.p.ProductName)
produces this
SELECT [LPA_L1].[CategoryId],
[LPA_L1].[Discontinued],
[LPA_L1].[ProductId],
[LPA_L1].[ProductName],
[LPA_L1].[QuantityPerUnit],
[LPA_L1].[ReorderLevel],
[LPA_L1].[SupplierId],
[LPA_L1].[UnitPrice],
[LPA_L1].[UnitsInStock],
[LPA_L1].[UnitsOnOrder]
FROM
(SELECT [LPLA_1].[CategoryID] AS [CategoryId],
[LPLA_1].[Discontinued],
[LPLA_1].[ProductID] AS [ProductId],
[LPLA_1].[ProductName],
[LPLA_1].[QuantityPerUnit],
[LPLA_1].[ReorderLevel],
[LPLA_1].[SupplierID] AS [SupplierId],
[LPLA_1].[UnitPrice],
[LPLA_1].[UnitsInStock],
[LPLA_1].[UnitsOnOrder]
FROM
[dbo].[Products] [LPLA_1] ) [LPA_L1] ORDER BY [LPA_L1].[ProductName] ASC
which runs fine but then you get
InvalidCastException
Unable to cast object of type 'System.Int16' to type 'Northwind.DAL.EntityClasses.ProductEntity'.
at lambda_method(Closure , Object[] , Int32[] )
at SD.LLBLGen.Pro.LinqSupportClasses.DataProjectorToObjectList`1.AddRowToResults(IList projectors, Object[] rawProjectionResult)
at SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List`1 valueProjectors, IGeneralDataProjector projector, IDataReader datasource, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, UniqueList`1 stringCache, Dictionary`2 typeConvertersToRun)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary`2 typeConvertersToRun)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteValueListProjection(QueryExpression toExecute)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.IEnumerable.GetEnumerator()
SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll version 3.5.12.0807
SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version 3.5.12.0824