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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:38:45+00:00 2026-06-14T07:38:45+00:00

Is there a way to call a SQL Server user defined function from LINQ

  • 0

Is there a way to call a SQL Server user defined function from LINQ to Entities while using Entity Framework v2?

I’ve found a way to do so using Entity Framework 4 (everything is explained in this blog post, but it appears that the EdmFunctionAttribute class is not available in EF4 🙁

If it is not possible, what is the best way to write a complex where clause in LINQ to entities? Here is an excerpt of my function to show you how complex it is :

IF @ageOfReferenceType = 3 or @ageToCompareType = 3 -- if one is expressed in weeks
    BEGIN
        --convert both to weeks
        SET @ageOfReference = @ageOfReference * CASE @ageOfReferenceType
                WHEN 1 THEN 52
                WHEN 2 THEN 4
                WHEN 3 THEN 1
            END
        SET @ageToCompare = @ageToCompare * CASE @ageToCompareType
                WHEN 1 THEN 52
                WHEN 2 THEN 4
                WHEN 3 THEN 1
            END
    END
    ELSE -- last solution, one is in years and the other in months
    BEGIN
        -- convert both to months
        SET @ageOfReference = @ageOfReference * CASE @ageOfReferenceType
                WHEN 1 THEN 12
                WHEN 2 THEN 1
            END
        SET @ageToCompare = @ageToCompare * CASE @ageToCompareType
                WHEN 1 THEN 12
                WHEN 2 THEN 1
            END
    END
END
IF @ageToCompare >= @ageOfReference
BEGIN
    RETURN 1
END
  • 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-14T07:38:46+00:00Added an answer on June 14, 2026 at 7:38 am

    It seems there is no solution to my problem, so i’m going to encapsulate the whole linq to entities query into a stored procedure, which will be able to call my UDF.

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

Sidebar

Related Questions

I'm using a Linq query to retrieve entities from an SQL server using the
Is there any way to call an action script function from an anchor which
Is there a way to call a HTTP web service from T-SQL (no SQLCLR)
I am using the Entity Framework with SQL Server Express 2008. When using the
I'm inserting a lot of data into SQL Server CE 4.0 using Entity Framework
is there any way to call servlet or make a gwt-rpc call from gwt
Is there a way to call multiple methods from backing bean in JSF? I
Is there a way to fix an orphaned user in a SQL 2005/2008 database
Is there any way to get the functionality of the Sql Server 2005+ Sequential
Is there a way to call send / recv passing in a vector ?

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.