Thoughts from Dan Miser RSS 2.0
 Friday, June 23, 2006
The following code snippet shows how to pick up the SQL that will be generated by a given LINQ query. The DataContext.GetQueryText() method makes this very easy. However, what we REALLY need is an easy way to go the other way, too. For example, given an adhoc string, generate the DLINQ query to allow further processing. I've looked through the Interactive Query sample, but that's not exactly what I want. The 2 main things wrong with it are that the baseQuery is already defined as an IQueryable variable, as opposed to a simple string; and the code to build up the expression tree is much too complex for every day needs. If we had a generic string to IQueryable method, we wouldn't need all of the expression code.


        static void Main(string[] args)
        {
            string s;
            var q  = from e in db.Employees select e.FirstName;
            
            s = db.GetQueryText(q);

            Console.WriteLine(s);
            Console.ReadLine();
        }
Friday, June 23, 2006 11:08:00 AM (Central Standard Time, UTC-06:00)  #    Comments [5] -
LINQ
Tracked by:
http://9no-information.info/34366335/index.html [Pingback]
http://9nu-information.info/94567292/canadian-amateur-radio-classified.html [Pingback]
http://9nh-information.info/14922012/index.html [Pingback]
http://9ni-information.info/89603269/index.html [Pingback]
http://9nk-information.info/91583859/index.html [Pingback]
http://9nc-information.info/17645113/design-ideas-for-home-gamerooms.html [Pingback]
http://9nb-information.info/13020841/index.html [Pingback]
http://9no-information.info/01876609/index.html [Pingback]
http://9oj-information.info/58819966/cam-depot.html [Pingback]
http://9ox-information.info/26400128/san-marco-theater-jacksonville-florida.html [Pingback]
http://9qj-information.info/68492571/consulenza-diritto-internazionale.html [Pingback]
http://9ot-information.info/41838594/index.html [Pingback]
http://9or-information.info/51478625/red-rock-hotel-casino.html [Pingback]
http://9ov-information.info/84926177/adding-a-dell-notebook-to-a-wireless-networ... [Pingback]
http://9qc-information.info/52336996/index.html [Pingback]
http://9ov-information.info/55312594/st-helens-game-fish-club.html [Pingback]
http://9oh-information.info/09926680/index.html [Pingback]
http://9rb-information.info/79104084/autographed-photo-of-wayne-gretsky.html [Pingback]
http://9sr-information.info/60472539/feste-sesso.html [Pingback]
http://9rm-information.info/98113745/index.html [Pingback]
http://9rm-information.info/42535703/richards-medical-company.html [Pingback]
http://9sn-information.info/40548042/index.html [Pingback]
http://9rg-information.info/21511947/building-a-home-for-100-000.html [Pingback]
http://9re-information.info/73123139/angus-dvd.html [Pingback]
http://9rr-information.info/23679165/index.html [Pingback]
http://9rw-information.info/56139344/high-school-bench-press-average-mass.html [Pingback]
http://9uafc-le-informazioni.info/71316323/index.html [Pingback]
http://9uafh-le-informazioni.info/69454371/ssis-unige.html [Pingback]
http://9uaet-le-informazioni.info/38184214/suisse-thermal.html [Pingback]
http://9uafe-le-informazioni.info/13364065/index.html [Pingback]
http://9uaet-le-informazioni.info/70533604/pavillion-8000.html [Pingback]
http://9uael-le-informazioni.info/93479384/index.html [Pingback]
http://9uafa-le-informazioni.info/00826748/index.html [Pingback]
http://9uaeo-le-informazioni.info/00992907/index.html [Pingback]
http://9uafi-le-informazioni.info/81918004/negozio-fotografia-padova.html [Pingback]
http://9uaft-le-informazioni.info/77947251/sentimento-morte-foscolo.html [Pingback]
http://9uagb-le-informazioni.info/93662362/hotel-wartburg.html [Pingback]
http://9uahp-le-informazioni.info/15887545/passiv-auf-deutsch.html [Pingback]
http://9uaga-le-informazioni.info/79107159/index.html [Pingback]
http://9uagg-le-informazioni.info/99937655/index.html [Pingback]
http://9uagt-le-informazioni.info/04199679/index.html [Pingback]
http://9uagn-le-informazioni.info/03847850/index.html [Pingback]
Friday, June 23, 2006 11:34:00 AM (Central Standard Time, UTC-06:00)
You can get some of the work done with QueryExpression.Lambda



See http://blogs.msdn.com/mattwar/archive/2006/05/10/594966.aspx
Friday, June 23, 2006 11:46:00 AM (Central Standard Time, UTC-06:00)
True, but if you look at that page, everyting is based off of existing IQueryable vars(see "IQueryable q = ...;" in the article). This is very similar to the Interactive Query sample.



Using Expressions, DataContext.CreateQuery, Lambdas, etc., one can build up the expression tree from a given string, but right now, it's a lot of work (unless I'm missing something).



What I'm hoping to see for the release is a very easy way to convert a string to an IQueryable, etc. that is DLINQ compliant. For example, what if you store your queries in an external source (config file, DB, XML, etc.) for use in your application? What about the general adhoc DLINQ query case?
Friday, June 23, 2006 12:09:00 PM (Central Standard Time, UTC-06:00)
> "what if you store your queries in an external source"



Doesn't this remove all the power of Linq, which comes from compile-time validated language-integrated queries?
Friday, June 23, 2006 12:24:00 PM (Central Standard Time, UTC-06:00)
Absolutely, that would certainly invalidate the compile-time, Intellisense, etc. side of things. But I've seen the requirement for adhoc come up too often over the years to think that this would *never* be used. Hopefully, it will be limited in use though. :)
Wednesday, June 28, 2006 9:55:00 AM (Central Standard Time, UTC-06:00)
One other follow up to non-compile time:



Building up an expression tree in an adhoc manner already invalidates that part (like in Interactive Query). What I'm saying (probably poorly) is that if you can do what they can do right now, why not open it all the way up?
Comments are closed.
Navigation
Archive
<May 2008>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 305
This Year: 20
This Month: 1
This Week: 0
Comments: 601
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)