linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
449 stars 39 forks source link

Need help in understanding if its possible to combine/concat/union a list<iqueryable> with projection subqueries? #344

Open aloksharma1 opened 10 months ago

aloksharma1 commented 10 months ago

Hi, i have different complex search queries defined in a lot of IQueryables, which i materialize using this model:

 public class SearchResults 
 {
     public string? Id { get; set; }
     public string? Title { get; set; }
     public string? Desc { get; set; }
     public string? Summary { get; set; }
     public string? AuthorName { get; set; }
     public string? AuthorProfile { get; set; }
     public IList<SearchImages>? Images { get; set; }
     public IList<SearchFiles>? Videos { get; set; }
     public IList<SearchFiles>? Files { get; set; }
     public IList<SearchLinks>? Links { get; set; }
     public IList<string>? Htmls { get; set; }
     public string? Slug { get; set; }
     public DateTimeOffset? DatePublished { get; set; }
     public DateTimeOffset? DateCreated { get; set; }
     public int ResultOrder { get; set; } = -1000;
     public string? Category { get; set; }
     public string? CategoryTrail { get; set; }
     public string? Type { get; set; }
     public string? ProviderTable { get; set; }
 }

right now i am doing IEnumerable materialization because ef core cannot union or concat this sort of queries it gives error Unable to translate set operation after client projection has been applied. Consider moving the set operation before the last 'Select' call.

And if i try to do ToLinqtoDB on this query it gives error on sequence cannot be translated.

here my SearchImages?, SearchFiles? etc field contains projection queries from various tables. Is there no efficient way to combine these results in single call?

MaceWindu commented 9 months ago

Not in current version. We are working on some improvements to parser in v6 version in this area which could help here.

Right, @sdanyliv ?

sdanyliv commented 9 months ago

sequence cannot be translated is serious error, it can be not fixed in new translator. Better to show your LINQ query.