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

  • SEARCH
  • Home
  • 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 7549699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:00:47+00:00 2026-05-30T10:00:47+00:00

I am looking to run a piece of code in the database. However there

  • 0

I am looking to run a piece of code in the database. However there is no supported translation to sql (using linq to sql).

How to convert this code logic ro either inline in linq or in a stored procedure? I have no knowledge of db and stored procedures so preferably I would like to write it in linq.

public Post GetPageOwner(int pageid)
{

    var posts = (from dp in db.Posts where dp.pageid == pageid select dp);
    var returned = posts;

    if (posts.Count() > 0)
    {
        var latest = posts.OrderByDescending(o => o.Date).FirstOrDefault();
        var sharedsamedayaslatest = (from p in posts where p.Date.AddDays(1) >= latest.Date select p);
        if (sharedsamedayaslatest.Count() > 1)
        {
            var followedpost = (from p in posts from s in db.Subscriptions where s.Subscriber == UID && s.Subscribedto == p.UserId select p);
            var count = followedpost.Count();
            if (count == 1)
            {
                returned = followedpost;
            }
            else if (count > 1)
            {
                returned = (from s in followedpost let reposts = GetPostReposts(s.id) let rating = GetPostRating(s.id) let score = reposts + rating orderby score descending select s);
            }
            else
            { 
                //no follower shared this post so return the most liked
                returned = (from s in sharedsamedayaslatest let reposts = GetPostReposts(s.id) let rating = GetPostRating(s.id) let score = reposts + rating orderby score descending select s);
            }
        }
        else
        {
            //no shares on the day the latest share
            returned = sharedsamedayaslatest;
        }
    }
    else
    {
        //only one post
        returned = posts;
    }

    return returned.FirstOrDefault(); //order by userid gets a random one
}
  • 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-05-30T10:00:49+00:00Added an answer on May 30, 2026 at 10:00 am

    May be something like this would work:

            public Post GetPageOwner(int pageid)
        {
    
            var posts = (from dp in db.Posts where dp.pageid == pageid select dp);
            var returned = posts;
    
            if (posts.Count() > 0)
            {
                var latest = posts.OrderByDescending(o => o.Date).FirstOrDefault();
                var sharedsamedayaslatest = (posts.Where(p => p.Date.AddDays(1) >= latest.Date));
                if (sharedsamedayaslatest.Count() > 1)
                {
                    var followedpost = (posts.SelectMany(p => db.Subscriptions, (p, s) => new {p, s}).Where(
                        @t => s.Subscriber == UID && s.Subscribedto == p.UserId).Select(@t => p));
                    var count = followedpost.Count();
                    if (count == 1)
                    {
                        returned = followedpost;
                    }
                    else if (count > 1)
                    {
                        returned = (followedpost.Select(s => new {s, reposts = GetPostReposts(s.id)}).Select(
                            @t => new {@t, rating = GetPostRating(s.id)}).Select(
                                @t => new {@t, score = reposts + rating}).OrderByDescending(@t => score).Select(@t => s));
                    }
                    else
                    {
                        //no follower shared this post so return the most liked
                        (sharedsamedayaslatest.Select(s => new {s, reposts = GetPostReposts(s.id)}).Select(
                            @t => new {@t, rating = GetPostRating(s.id)}).Select(
                                @t => new {@t, score = reposts + rating}).OrderByDescending(@t => score).Select(@t => s)) = returned;
                    }
                }
                else
                {
                    //no shares on the day the latest share
                    returned = sharedsamedayaslatest;
                }
            }
            else
            {
                //only one post
                returned = posts;
            }
    
            return returned.FirstOrDefault(); //order by userid gets a random one
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking into using only a ddl to run my query, not a
I have a piece of templated code that is never run, but is compiled.
I have a need to run a piece of code every 120 seconds. I
I'm looking for a piece of code which behaves a bit like a singleton
I need to convert our existing iPhone 3-D action game code to run on
I'm looking to run a script on a page that puts each piece of
I'm looking to run this for loop, but it takes an unacceptably long time
I'm looking to run Redmine, a Ruby on Rails app, on a VPS windows
I'm looking to run a Jabber server on a Windows 2003 server(web farm) and
I'm looking to run some un-verified scripts (written in a yet-to-be-determined language, but needs

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.