Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:50:29+00:00 2026-06-04T17:50:29+00:00

I have the following code. The function has a lot of Linq calls and

  • 0

I have the following code. The function has a lot of Linq calls and I had help on putting this into place.

    public IList<Content.Grid> Details(string pk)
    {
        IEnumerable<Content.Grid> details = null;
        IList<Content.Grid> detailsList = null;
        var data = _contentRepository.GetPk(pk);
        var refType = this.GetRefType(pk);
        var refStat = this.GetRefStat(pk);
        var type = _referenceRepository.GetPk(refType);
        var stat = _referenceRepository.GetPk(refStat);
        details =
        from d in data
        join s in stat on d.Status equals s.RowKey into statuses
        from s in statuses.DefaultIfEmpty()
        join t in type on d.Type equals t.RowKey into types
        from t in types.DefaultIfEmpty()
        select new Content.Grid
        {
            PartitionKey = d.PartitionKey,
            RowKey = d.RowKey,
            Order = d.Order,
            Title = d.Title,
            Status = s == null ? null : s.Value,
            StatusKey = d.Status,
            Type = t == null ? null : t.Value,
            TypeKey = d.Type,
            Link = d.Link,
            Notes = d.Notes,
            TextLength = d.TextLength
        };
        detailsList = details
                .OrderBy(item => item.Order)
                .ThenBy(item => item.Title)
                .Select((t, index) => new Content.Grid()
                {
                    PartitionKey = t.PartitionKey,
                    RowKey = t.RowKey,
                    Row = index + 1,
                    Order = t.Order,
                    Title = t.Title,
                    Status = t.Status,
                    StatusKey = t.StatusKey,
                    Type = t.Type,
                    TypeKey = t.TypeKey,
                    Link = t.Link,
                    Notes = t.Notes,
                    TextLength = t.TextLength,

                })
                 .ToList();
        return detailsList;

    }

The first uses one format for Linq and the second another. Is there some way that I could simplify and/or combine these? I would really like to make this code simpler but I am not sure how to do this. Any suggestions would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:50:31+00:00Added an answer on June 4, 2026 at 5:50 pm

    Of course you can combine them. The Linq keywords such as from, where and select get translated into calls like the Extension methods that you call below, so effectively there’s no difference.

    If you really want to combine them, the quickest way is to put () around the first query, then append the method calls you use on details in the second query. Like this:

    detailsList =
            (from d in data                    // <-- The first query
             // ...
             select new Content.Grid
             {
                 // ...
             })
             .OrderBy(item => item.Order)    // <-- The calls from the second query
             .ThenBy(item => item.Title)
             .Select((t, index) => new Content.Grid()
             {
                 //...
             }).ToList();
    

    But i think that would be ugly. Two queries are just fine IMO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have the following code: function Person(){ this.age = 30; } function Stats(){ this.age
I have the following code function generate_pdf() { $fdf_data_strings = $this->get_hash_for_pdf(); #$fdf_data_names = array('49a'
I have the following code: function toggleChecked(status) { $(.checkbox).each( function() { $(this).attr(checked,status); }) }
I have the following code: function callIframe(type, cat) { var send = false; var
I have the following code: function show(){ var a=document.getElementById('somediv').style.display; a=block; } The above code
Suppose I have the following code function myFunction(param, callback) { ... if (err) {
I have written the following code function byId(id) { return document.getElementById(id); } function addElm(root,elm)
I have the following code: protected function safePath($path) { $path = (string) $path; $path
I have the following code: $(function () { $(#ARO).load('/DA.aspx?section=ARO #ARO', function() { DoSomething1(); });

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.