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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:27:20+00:00 2026-05-13T00:27:20+00:00

I’m working with a client who wants to mix LINQ to SQL with their

  • 0

I’m working with a client who wants to mix LINQ to SQL with their in-house DAL. Ultimately they want to be able to query their layer using typical LINQ syntax. The point where this gets tricky is that they build their queries dynamically. So ultimately what I want is to be able to take a LINQ query, pull it apart and be able to inspect the pieces to pull the correct objects out, but I don’t really want to build a piece to translate the ‘where’ expression into SQL. Is this something I can just generate using Microsoft code? Or is there an easier way to do this?

  • 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-13T00:27:20+00:00Added an answer on May 13, 2026 at 12:27 am

    (you mean just LINQ, not really LINQ-to-SQL)

    Sure, you can do it – but it is massive amounts of work. Here’s how; I recommend “don’t”. You could also look at the source code for DbLinq – see how they do it.

    If you just want Where, it is a bit easier – but as soon as you start getting joins, groupings, etc – it will be very hard to do.


    Here’s just Where support on a custom LINQ implemention (not a fully queryable provider, but enough to get LINQ with Where working):

    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using System.Reflection;
    
    namespace YourLibrary
    {
        public static class MyLinq
        {
            public static IEnumerable<T> Where<T>(
                this IMyDal<T> dal,
                Expression<Func<T, bool>> predicate)
            {
                BinaryExpression be = predicate.Body as BinaryExpression;
                var me = be.Left as MemberExpression;
                if(me == null) throw new InvalidOperationException("don't be silly");
                if(me.Expression != predicate.Parameters[0]) throw new InvalidOperationException("direct properties only, please!");
                string member = me.Member.Name;
                object value;
                switch (be.Right.NodeType)
                {
                    case ExpressionType.Constant:
                        value = ((ConstantExpression)be.Right).Value;
                        break;
                    case ExpressionType.MemberAccess:
                        var constMemberAccess = ((MemberExpression)be.Right);
                        var capture = ((ConstantExpression)constMemberAccess.Expression).Value;
                        switch (constMemberAccess.Member.MemberType)
                        {
                            case MemberTypes.Field:
                                value = ((FieldInfo)constMemberAccess.Member).GetValue(capture);
                                break;
                            case MemberTypes.Property:
                                value = ((PropertyInfo)constMemberAccess.Member).GetValue(capture, null);
                                break;
                            default:
                                throw new InvalidOperationException("simple captures only, please");
                        }
                        break;
                    default:
                        throw new InvalidOperationException("more complexity");
                }
                return dal.Find(member, value);
            }
        }
        public interface IMyDal<T>
        {
            IEnumerable<T> Find(string member, object value);
        }
    }
    namespace MyCode
    {
        using YourLibrary;
        static class Program
        {
            class Customer {
                public string Name { get; set; }
                public int Id { get; set; }
    
            }
            class CustomerDal : IMyDal<Customer>
            {
                public IEnumerable<Customer> Find(string member, object value)
                {
                    Console.WriteLine("Your code here: " + member + " = " + value);
                    return new Customer[0];
                }
            }
            static void Main()
            {
                var dal = new CustomerDal();
                var qry = from cust in dal
                          where cust.Name == "abc"
                          select cust;
    
                int id = int.Parse("123");
                var qry2 = from cust in dal
                          where cust.Id == id // capture
                          select cust;
    
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I want to construct a data frame in an Rcpp function, but when I
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.