• Home
  • About the Author

GIS and .NET Development

Rants on GIS, .NET, and life in general

Feeds:
Posts
Comments

My Head Hurts – Making LINQ Let You IN

December 31, 2008 by homebrutrout

So my head is all turned around this morning and it honestly has nothing to do with our proximity to the new year.  I’ve been whacking around building the IRepository layer for an MVC + ESRI JS API application and SubSonic has been giving me fits trying to join across multiple tables with multiple T-SQL IN statements.  I’ve been test driving SubSonic 3 which is very LINQ-y indeed making sure it will handle some of the more hoopty portions of an existing data schema we’re working in.

Well I wanted to do a query of the sort “SELECT * FROM MyTable INNER JOIN MyManyTable ON MYTable.IDColumn = MyManyTable.MyTableIDColumn WHERE MyManyTable.SomeOtherColumn IN (values)”.  There’s acutally a couple of INNERJOIN terms in there but you get the picture…clearly doing repetitive ORs over a values array is just ugly and frankly smells bad.  Well I went a googlin’ and didn’t find much…perhaps I’m loosing my touch with the search terms or something.   After a frustrating day yesterday trying to get LINQ to generate me an in statement, a colleague passed along a web link that revealed the marvels of the Contains operator.

Turns out the answer was under my nose the entire time, right on the blog of the SubSonic creator and mastermind…  The trick is to use the contains operator and turn your where clause upside down.  I won’t plagiarize the code here but for my own future reference and sanity as well as the reader’s here’s Rob’s solution to the problem along with Greg Duncan’s epiphany.  Also note that both these guys beat their heads about this just like I did which is some small measure of consolation…

Posted in Uncategorized | 1 Comment

One Response

  1. on January 14, 2009 at 10:37 am Handling Recursive Relates with SubSonic and LINQ « GIS and .NET Development

    [...] dealt with the inner join issue in a previous post here. But let’s consider the recursive foreign key issue. Consider a portion of our data model [...]



Comments are closed.

  • Categories

    • .NET (16)
    • Agile (10)
    • ArcGIS Server (2)
    • ArcSDE (1)
    • Code Gen (2)
    • CodeGen (2)
    • Design Patterns (12)
    • ESRI (13)
    • General GIS (23)
    • GeoWeb (5)
    • Interoperability (2)
    • life (8)
    • MVC (9)
    • Offshore (3)
    • REST (1)
    • SubSonic (2)
    • Tech Talk (4)
    • Uncategorized (11)
    • Usability (4)
    • Utilities (5)
    • VE (1)
  • Archives

    • October 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • September 2008
    • July 2008
    • June 2008
    • May 2008
    • March 2008
    • February 2008
    • January 2008
  • Disclaimer

    The posts on this site represent my personal thoughts and opinions at the time of original posting. These views should in no way be construed to be those of my employer. All original work on this site is distributed under the Creative Commons License . Work or concepts attributed to others are licensed separately by the original author.
  • Pages

    • About the Author
  •  

    December 2008
    M T W T F S S
    « Nov   Jan »
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • Admin

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.com

Blog at WordPress.com.

Theme: Mistylook by Sadish.