You must Sign In to post a response.
  • Category: LINQ

    Data formating using linq

    i have a set of records stored in list its about 24 items i need in three rows

    for exampple its looks like



    id name status
    2 Masters NULL
    12 Transactions NULL
    13 Reports NULL
    4 Projects TRUE
    5 Team TRUE
    6 Employee Category TRUE
    7 Employee TRUE
    8 JobType TRUE
    9 PackType TRUE
    10 Price TRUE
    11 Currency TRUE


    I need like below how i can get using linq

    Module Name sub modules
    Master [4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]
    Transactions [4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]
    Reports [4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]-[4,Projects,true]
  • #768577
    You can use given code snippet for multiple record using linq
    private static void Main(string[] args)
    {
    var userProfiles = GenerateUserProfiles();
    var idList = GenerateIds();
    var stopWatch = new Stopwatch();
    stopWatch.Start();
    userProfiles.Join(idList, up => up.ID, id => id, (up, id) => up).ToArray();
    Console.WriteLine("Elapsed .Join time: {0}", stopWatch.Elapsed);
    stopWatch.Restart();
    userProfiles.Where(up => idList.Contains(up.ID)).ToArray();
    Console.WriteLine("Elapsed .Where .Contains time: {0}", stopWatch.Elapsed);
    Console.ReadLine();
    }

    private static IEnumerable<int> GenerateIds()
    {
    for (int i = 100; i > 0; i--)
    {
    yield return i;
    }
    }

    private static IEnumerable<UserProfile> GenerateUserProfiles()
    {
    for (int i = 0; i < 100; i++)
    {
    yield return new UserProfile {ID = i};
    }
    }


Sign In to post your comments