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

The Archive Base Latest Questions

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

.NET 3.5, C# I have a web app with a search feature. Some of

  • 0

.NET 3.5, C#

I have a web app with a ‘search’ feature. Some of the fields that are searchable are first-class columns in the table, but some of them are in fact nested fields inside an XML data type.

Previously, I built a system for dynamically constructing the SQL for my search. I had a nice class hierarchy that built SQL expressions and conditional statements. The only problem was it was not safe from SQL injection attacks.

I was reading Rob Conery’s excellent article which pointed out that multiple queries can combined into a single TSQL query for the server if the IQueryable result is never enumerated. This got me to thinking that my dynamic search construction was much too complicated – I just needed to combine multiple LINQ expressions.

For example (contrived):

Author:     ID (int),     LastName (varchar(32)),      FirstName (varchar(32))      context.Author.Where(xx => xx.LastName == 'Smith').Where(xx => xx.FirstName == 'John') 

Results in the following query:

SELECT [t0].[ID], [t0].[LastName], [t0].[FirstName] FROM [dbo].[Author] AS [t0] WHERE ([t0].[LastName] = Smith) AND ([t0].[FirstName] = John) 

I realized this might be the perfect solution for a simple dynamic query generation that’s safe from SQL injection – I’d just loop over my IQueryable result and execute additional conditionals expressions to get my final single-execution expression.

However, I can’t find any support for evaluation of XML data. In TSQL, to get a value from an XML node, we would do something like

XMLField.value('(*:Root/*:CreatedAt)[1]', 'datetime') = getdate()  

But I can’t find the LINQ to SQL equivalent of creating this evaluation. Does one exist? I know I can evaluate all non-XML conditions DB side, and then do my XML evaluations code side, but my data are large enough that A) that’s a lot of network traffic to drag on performance and B) I’ll get out-of-memory exceptions if I can’t evaluate the XML first DB side to exclude certain result sets.

Ideas? Suggestions?

Bonus question – If XML evaluation is in fact possible DB side, what about FLWOR support?

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

    Now that is an interesting question.

    Right now, you cannot instruct SQL Server to perform XML functions directly from Linq. However, you can get Linq to use user defined functions… so, you could setup a udf to process the xml, get the right data, etc, and then use that in your Linq expresion. This will execute on the server and should do what you want. There’s an important limitation, though: The XML path you’re looking for (the first parameter to xmlColumn.value or similar) has to be built into the function because it has to be a string literal, it can’t be built from an input parameter (for instance). So you can use UDFs for getting fields you know about when writing the UDF, but not as a general-purpose way to get data from XML columns.

    Check out the Supporting User Defined Functions (UDFs) section of Scott Gutherie’s excellent Blog series on Linq to SQL for more info on implementation.

    Hope this helps.

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

Sidebar

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a number of ways you can do this:… May 11, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer I don't think that there is an automatic way of… May 11, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer As @josh mentioned, you probably want to submit the form… May 11, 2026 at 4:08 pm

Related Questions

Background: I developed a web app in ASP.Net 3.5 in C#. It runs great
I have written a server/client application using sockets in C# for .NET 3.5. I'm
I have been asked up to come up with a state management strategy for
I have an application dependent on some internal web services, and so we want

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.