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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:51:39+00:00 2026-05-13T13:51:39+00:00

Currently im trying to make my query short with reusable peice of code like

  • 0

Currently im trying to make my query short with reusable peice of code like this to check for post if it’s eligible to display.

    // Logic to check if post is eligible for display
    public bool isEligibleForDisplay(Post n)
    {
        var pubDate = n.PUBLISH_DATE ?? DateTime.MinValue;
        var endDate = n.END_DATE ?? DateTime.MaxValue;
        var correctState = (n.STATE == PostState.Publish || n.STATE == PostState.Furture);
        var dateInRange = (DateTime.Now >= pubDate && DateTime.Now <= endDate);
        return correctState && dateInRange;
    }

my linq look like this:

var q = from n in _db.Posts
                    where isEligibleForDisplay(n)
                    group n by n.POST_ID into g
                    select g.OrderByDescending(t => t.CREATE_DATE).First();
            return q.Take(quantity);

I ran into “No supported translation in SQL” problem for the first time of using linq to sql, I am just wondering if there are anyway that can use as a work around for this case, which could be troublesome if I include whole lot of those checking logic into my query everytime.

I’m so looking forward for a reply. Thanks!

  • 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-13T13:51:40+00:00Added an answer on May 13, 2026 at 1:51 pm

    You can create a function on your SQL server called isEligibleForDisplay that does the SQL equivalence of these checkes and add that to your dbml file.

    I haven’t tested this, but I’m thinking the easiest would be if you create a function where you pass the values you want, rather than the whole record, and I think something like this might work:

    CREATE FUNCTION isEligibleForDisplay(
        @publishDate DATETIME,
        @endDate DATETIME,
        @state TINYINT -- correct me if i'm wrong...
    ) RETURNS bit
    
    AS
    
    BEGIN
    
        DECLARE @return bit
        DECLARE @dateStart DATETIME, @dateEnd DATETIME
    
        SET @return = 0
    
        SET @dateStar t= COALESCE(@publishDate, CONVERT(DATETIME, '1900-01-01'))
        SET @dateEnd = COALESCE(@endDate, CONVERT(DATETIME, '9999-12-31'))
    
        IF getdate() BETWEEN @dateStart AND @dateEnd
        BEGIN
    
            IF @state IN(1,3) -- or whatever the int representations of your enum are
                SET @return = 1
    
        END
    
    
        RETURN @return
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to make a sectioned table like this: Section 1: Entry
Currently I'm trying to make a flowchart, this is the code I've got so
We're currently stuck trying to make a simple (?) SQL query. We have these
I'm trying to make it so that this code shows however many rows there
I'm currently trying to make a set of conversion functions which, through one call,
I'm currently trying to make an orientation calculator in java and I'm having a
I am currently trying to make a dropbox-esque application from a tutorial and I
I am currently trying to make an application that allows the user to create
i'm currently trying to make a asp.net mvc3 app. in the sample application which
The graph I'm currently trying to make falls a little between two stools. I

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.