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 7520943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:09:14+00:00 2026-05-30T02:09:14+00:00

I am using linq to sql. I am running a query which uses a

  • 0

I am using linq to sql. I am running a query which uses a function to return the right record. I am using a function so I can use if statement which I dont know how to do it within the linq clause. The code is copied below. It returns an error: “GetPageOwner(int 32) has no supported translation to sql” what am i doing wrong? How to fix it to get the same results?

   return (from page select new Result
        {

            pageOwner = GetPageOwner(page.page_id)
        });


    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-30T02:09:15+00:00Added an answer on May 30, 2026 at 2:09 am

    Linq to sql has to translate functions from .net into sql. Not all .net functions have an equivalent in sql, and ones written by you definitely don’t have one.

    That being said you can implement your function as a stored procedure and use it in your linq query.

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

Sidebar

Related Questions

When using linq to sql are there any benefits of using subsonic's active record
im using linq to sql i have a Mission entity, which holds a collection
Using Linq to Sql how do I group the following table (entidadeProdutosFornecedores) and return
I'm using linq-to-sql for a query like this: public static List<MyModel> GetData(int TheUserID, DateTime
I am using Linq-To-Entities to do a query which is returning only 947 rows
I have a WPF Linq-to-SQL project which I have been developing using MS Visual
How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*,
Using LINQ to SQL, I have an Order class with a collection of OrderDetails.
Using LINQ to SQL db.Products.Where(c => c.ID == 1).Skip(1).Take(1).ToList(); executes SELECT [t1].[ID], [t1].[CategoryID], [t1].[Name],
using Linq-to-SQL I'd like to prefetch some data. 1) the common solution is to

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.