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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:10:30+00:00 2026-05-10T21:10:30+00:00

i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from

  • 0

i have this in my BlogRepository

public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts()     {         var query = from p in db.Posts                     let categories = GetCategoriesByPostId(p.PostId)                     let comments = GetCommentsByPostId(p.PostId)                     select new Subnus.MVC.Data.Model.Post                     {                         Categories = new LazyList<Category>(categories),                         Comments = new LazyList<Comment>(comments),                         PostId = p.PostId,                         Slug = p.Slug,                         Title = p.Title,                         CreatedBy = p.CreatedBy,                         CreatedOn = p.CreatedOn,                         Body = p.Body                     };         return query;     } 

and

public IQueryable<Subnus.MVC.Data.Model.Comment> GetCommentsByPostId(int postId)     {         var query = from c in db.Comments                     where c.PostId == postId                     select new Subnus.MVC.Data.Model.Comment                     {                         Body = c.Body,                         EMail = c.EMail,                         Date = c.CreatedOn,                         WebSite = c.Website,                         Name = c.Name                     };          return query;     }  private IQueryable<Subnus.MVC.Data.Model.Category> GetCategoriesByPostId(int postId)     {         var query = from c in db.Categories                     join pcm in db.Post_Category_Maps on c.CategoryId equals pcm.CategoryId                     where pcm.PostId == postId                     select new Subnus.MVC.Data.Model.Category                     {                         CategoryId = c.CategoryId,                         Name = c.Name                     };         return query;     } 

and when i aplly this filter

namespace Subnus.MVC.Data {  public static class BlogFilters  {     public static IQueryable<Post> WherePublicIs(this IQueryable<Post> qry,bool state)     {          return from p in qry                where p.IsPublic == state                select p;     }  } 

}

all this is in the same namespace if that help namespace Subnus.MVC.Data

when i try to do this

public class BlogService : IBlogService { ...     public IList<Post> GetPublicPosts()     {          return repository.GetPosts().WherePublicIs(true).ToList();     }  ...  } 

that is in the namespace Subnus.MVC.Service it throws the error

Method 'System.Linq.IQueryable`1[Subnus.MVC.Data.Model.Comment] GetCommentsByPostId(Int32)' has no supported translation to SQL. 
  • 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. 2026-05-10T21:10:31+00:00Added an answer on May 10, 2026 at 9:10 pm

    You are calling GetCommentsByPostId within what is ultimately an expression tree. That tree, when composed in BlogService.GetPublicPosts, is converted to SQL.

    During that conversion, it is just a method call, nothing more. Linq to Sql understands certain method calls, and yours is not one of them. Hence the error.

    On the surface, this seems like it should work. You write reusable queries and compose them from other queries. However, what you are actually saying is: ‘during the processing of each row on the database server, call this method’, which it obviously can’t do. The fact that it takes an IQueryable<T> and returns an IQueryable<T> does not make it special.

    Think about it this way: you are passing postId to GetCategoriesByPostId. You can’t call that method until you have a postId, and you don’t have one of those until you are on the server in the query.

    You would probably need to define common Expression<> instances for the sub-queries and use those in the composition. I haven’t thought about what this would look like but it’s certainly doable.

    Edit:

    If you replace

    let categories = GetCategoriesByPostId(p.PostId) let comments = GetCommentsByPostId(p.PostId) ... Categories = new LazyList<Category>(categories), Comments = new LazyList<Comment>(comments), 

    with

    Categories = new LazyList<Category>(GetCategoriesByPostId(p.PostId)), Comments = new LazyList<Comment>(GetCommentsByPostId(p.PostId)), 

    the query will no longer throw an exception.

    This is because let declares range variables, which are in scope for each row. They must be calculated on the server.

    Projections, however, allow you to put arbitrary code in assignments, which is then executed while building results on the client. This means both methods will be called, each of which will issue its own query.

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

Sidebar

Related Questions

Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have this function // add history paths and save data function AddPath( strTag,
Have this dictionay retrieving values from DataTable: Dictionary<string,string> meta= ds.Tables[1].Select(key<>'format').AsEnumerable().ToDictionary(k=>k.Field<string>(0),v=>v.Field<string>(1)); How would I apply
I have this javascript code: function checkUploadedFile() { var inputFile = $(#fuUploadProfile).val(); if (inputFile
Have this print output from print_r($theobject); SimpleXMLElement Object ( [@attributes] => Array ( [label]
I have this regular expression that extracts meta tags from HTML documents but it
I have this script- import lxml from lxml.cssselect import CSSSelector from lxml.etree import fromstring
have this code: $products = $feed->_xpath->query( //cf:vehicle ); foreach( $products as $product ) {
Have this code: var gradient = ctx.createLinearGradient(0,0, 20, 0); gradient.addColorStop(0.8, rgb(250,250,0)); gradient.addColorStop(1, rgb(150,150,0)); ctx.fillStyle
I have this query in MySQL and I need to convert this to rails

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.