Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# entity framework order by array

var countByOtherId = db.EntityToOrder
    .GroupBy(e => e.OtherId)
    .Select(g => new { ID = g.Key, Count = g.Count() })
    .ToDictionary(e => e.ID, e => e.Count);

var other = new Dictionary<long, string>();
int skipCount = startIndex, useCount = 0;
foreach (var e in db.OtherEntity.OrderBy(e => e.Name))
{
    int count;
    if (!countByOtherId.TryGetValue(e.ID, out count)) continue;
    if (skipCount > 0 && other.Count == 0)
    {
        if (skipCount >= count) { skipCount -= count; continue; }
        count -= skipCount;
    }
    other.Add(e.ID, e.Name);
    if ((useCount += count) >= pageSize) break;
}


var entities = db.EntityToOrder
    .Where(e => other.Keys.Contains(e.OtherId))
    .AsEnumerable()
    .Select(e => new EntityToOrder { ID = e.ID, Name = e.Name, 
        OtherId = e.OtherId, OtherName = other[e.OtherId] })
    .OrderBy(e => e.OtherName).ThenBy(e => e.Name)
    .Skip(skipCount).Take(pageSize)
    .ToList();
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# Showing a hidden WPF window 
Csharp :: how to get scene color to work with urp unity 
Csharp :: Click an HTML link inside a WebBrowser Control 
Csharp :: c# add field to expando object 
Csharp :: csgo crashes at retrieving game data 
Csharp :: lista generica como parametro de un metodo en c# 
Csharp :: list to array f# 
Csharp :: OIUJHKJHSKAL::KSAJ 
Csharp :: How do I remove a String Array from a List in C# 
Csharp :: how download file from internet and move it to folder with c# 
Csharp :: player movement unity 3d script 
Csharp :: virtual list entity framework 
Csharp :: C# how to search textfile and append 
Csharp :: how to make a destroy reference in unity 
Csharp :: copy array to array in c# 
Csharp :: c# message box carriage return 
Csharp :: DataTable GetErrors 
Csharp :: particles are pink - creating tex and material 
Csharp :: Unity Hollow Blender Model 
Csharp :: MVC Razor check for postback 
Csharp :: c# deeply related children 
Csharp :: remote webdriver dotnet 
Csharp :: Game of two stack c# 
Csharp :: Diplay player final score in new scene in unity 
Csharp :: unity number generator 
Csharp :: c# unary operators 
Csharp :: how can find github issue closed date 
Csharp :: how to store more precise data then float c# 
Csharp :: List picking records from database 
Csharp :: custom convert list object to other object c# 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =