monstertjie_za
monstertjie_za

Reputation: 7823

LinqToDb: Rank is server-side method

I am trying to use linq2db.EntityFrameworkCore for some of its windowing functions, such as RANK().

Below is my implementation:

var abc = (from tl in _repo.Context.TransferLink
                 join tlt in _repo.Context.TransferLinkType on new { TLinkId = tl.TransferLinkTypeId, EType = "Deviance" } equals new { TLinkId = tlt.TransferLinkTypeId, EType = tlt.EnumTransferLinkType }
                 //let duplicateCount = _repo.Context.TransferLink.Where(tl1 => tl1.SecondaryTransferId != null && tl.SecondaryTransferId != null &&
                 //tl1.SecondaryTransferId == tl.SecondaryTransferId.Value).Count()
                 where
                   (allTransferIds.Contains(tl.PrimaryTransferId) || allTransferIds.Contains(tl.SecondaryTransferId)) &&
                   !tl.Archived
                 select new
                 {
                     TransferLinkId = tl.TransferLinkId,
                     TransferLinktypeId = tl.TransferLinkTypeId,
                     PrimaryTransferId = tl.PrimaryTransferId,
                     SecondaryTransferId = tl.SecondaryTransferId,
                     DuplicateCount = Sql.Ext.Count(tl.TransferLinkId)
                                          .Over()
                                          .PartitionBy(tl.SecondaryTransferId)
                                          .ToValue()
                     UpdatedDate = tl.UpdatedDate,
                     RankVal = Sql.Ext.Rank()
                                  .Over()
                                  .PartitionBy(tl.TransferLinkTypeId, tl.SecondaryTransferId)
                                  .OrderByDesc(tl.UpdatedDate)
                                  .ThenBy(tl.TransferLinkId)
                                  .ToValue()
                 }).ToList();

This code throws the exception:

Rank is server-side method

I have tried searching for a solution, but could not find any.

Any idea?

Upvotes: 2

Views: 384

Answers (1)

Svyatoslav Danyliv
Svyatoslav Danyliv

Reputation: 27436

For using linq2db.EntityFrameworkCore you have to switch to library's LINQ provider. It can be done by simple ToLinqToDB() call.

var query = /* some EF Core query */

query = query.ToLinqToDB();

var result = query.ToList();

Upvotes: 5

Related Questions