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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:39:57+00:00 2026-05-10T20:39:57+00:00

We have scalar functions in our database for returning things like number of tasks

  • 0

We have scalar functions in our database for returning things like ‘number of tasks for a customer’ or ‘total invoice amount for a customer’.

We are experimenting and looking to try to do this w/o stored procedures … normally we would just call this function in our stored procedure and return it as a single value.

Is there a way to use or access scalar functions with LINQ to SQL? If so, I would be interested in see an example of how to … if not, how would it be best to handle this type of situation … if it is even doable.

  • 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-10T20:39:57+00:00Added an answer on May 10, 2026 at 8:39 pm

    LINQ-to-SQL supports use with UDFs, if that is what you mean. Just drag the UDF onto the designer surface and you’re done. This creates a matching method on the data-context, marked [Function(..., IsComposable=true)] or similar, telling LINQ-to-SQL that it can use this in queries (note that EF doesn’t support this usage).

    You would then use it in your query like:

    var qry = from cust in ctx.Custs            select new {Id = cust.Id, Value = ctx.GetTotalValue(cust.Id)}; 

    which will become TSQL something like:

    SELECT t1.Id, dbo.MyUdf(t1.Id) FROM CUSTOMER t1 

    (or there-abouts).

    The fact that it is composable means that you can use the value in queries – for example in a Where()/WHERE – and so reduce the data brought back from the server (although obviously the UDF will still need to be executed in some way).

    Here’s a similar example, showing a pseudo-UDF at use on a data-context, illustrating that the C# version of the method is not used.

    Actually, I’m currently looking at such UDFs to provide ‘out of model’ data in a composable way – i.e. a particular part of the system needs access to some data (that happens to be in the same database) that isn’t really part of the same model, but which I want to JOIN in interesting ways. I also have existing SPs for this purpose… so I’m looking at porting those SPs to tabular UDFs, which provides a level of contract/abstraction surrounding the out-of-model data. So because it isn’t part of my model, I can only get it via the UDF – yet I retain the ability to compose this with my regular model.

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

Sidebar

Related Questions

I have a small text file that I'd like to read into a scalar
I have a snippet to create a 'Like' button for our news site: <iframe
I have an implicit scalar field defined in 2D, for every point in 2D
I have an application where I would like to have mixed Java and Scala
Have just started using Google Chrome , and noticed in parts of our site,
I have a user defined function in a SQL Server 2005 database which returns
I have a recursive scalar function that needs to update a record in another
I'm struggling with applying the visitor pattern on some objects that have scalar members
I have a c function (dbread) that reads 'fields' from a 'database'. Most of
In our case we have some business logic that looks into several tables in

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.