Efcore: Query: Simplify aliases for complex projection if being used in order by clause in new pipeline

Created on 6 Nov 2019  路  5Comments  路  Source: dotnet/efcore

query:

ss.Set<Customer>().Select(c => new DTO<string> { Property = c.CustomerID + c.City }).OrderBy(n => n.Property)

translation:

SELECT [c].[CustomerID] + [c].[City] AS [Property]
FROM [Customers] AS [c]
ORDER BY [c].[CustomerID] + [c].[City]

expected translation:

SELECT [c].[CustomerID] + [c].[City] AS [Property]
FROM [Customers] AS [c]
ORDER BY [Property]

This used to work in the old pipeline - see #6703

area-query type-enhancement

All 5 comments

It used work in old pipeline with a lot of bugs :trollface:

Should be easy step in posttranslation.

Any workaround?

I麓m struggling to get containstable rank in an fromsqlinterpolated, wish to at last orderby Rank, as 'Rank' is not a property of my entity and is generated

Appreciate your help.

@lixaotec the queries should still work, just the sql we generate is not optimal. Can you provide more info on what exactly you are trying to do and how are you trying to do this? - full code listing would be the best.

I wish to project afromsqlinterpolated directly onto a DTO, however its seems not possible as I need to indicate the entity in Db.Set() ...
Perhaps this breaks the pipeline concept of EFCore, but some queries are too complex and don麓t need to live within the entities context.

In short, retrieving Rank information from a fromsqlinterpolate with FullTextSearch containstable is not possible if Rank isn麓t present as a column in the entity.

I found out that EFCore supports Keyless entity, a thing that seem to allow such thing. as I define an entity that has a Rank field, not necessarily an entity. But the strange thing is that I still have to register it in modelbuilder.

Keyless seem to be the closer concept near to making EFCore know a DTO class.
Wish to hear if is that a good practice.

Thanks

@lixaotec See #10753

Was this page helpful?
0 / 5 - 0 ratings