SubSonic Forums
All Your Database Are Belong To Us

Wheres and NOT IN

Latest post 05-23-2008 4:21 PM by del. 3 replies.
  • 05-22-2008 4:44 PM

    • DanKline
    • Top 50 Contributor
    • Joined on 12-13-2006
    • West Bend, WI
    • Posts 46

    Wheres and NOT IN

     As in Where's the NOT IN.  With all the capability added to the query, it seems like there should be a "Notn" on subsonic query.  I've tried to work around it with Inline query, but I think it was too much for the query parser.

    I've also tried a SP with a strongly type class, but I come back with the right count, but all my values are 0.   Arggghhh  the pain of learning.   

    NIX the NotIN comment.  I found it and I'm trying it now.

    If you're going to look back and laugh... You might as well laugh now!

    Filed under:
  • 05-22-2008 6:25 PM In reply to

    • del
    • Top 500 Contributor
    • Joined on 03-03-2008
    • Posts 10

    Re: Wheres and NOT IN

    Please post your results.  I was not able to get it to work, as I posted in http://forums.subsonicproject.com/forums/p/3213/13319.aspx#13319.  I'm getting the error 'Must declare the scalar variable "@notIn1"'.  I had to implement an inefficient reverse IN query instead.

     

  • 05-22-2008 8:30 PM In reply to

    • DanKline
    • Top 50 Contributor
    • Joined on 12-13-2006
    • West Bend, WI
    • Posts 46

    Re: Wheres and NOT IN

     Here's what I did ... who knows if it's efficient.  After working on it all afternoon, I'm glad it works:

    1. Select  the list to be excluded
    2. convert the collection to an array of objects
    3. pass the array to the new collection selection as an array attached to the NotIN.

    You may have to stumble through the variables ... it's not Northwind

     // Populate the Binding Sources for the related Tabs
    // Retrieve Bindings for the LZone SubScription tab
    // first the lookup

    // Get the exclude list

     

    OrionDB.LZLinkCollection nlzcol = new InlineQuery().
    ExecuteAsCollection<OrionDB.
    LZLinkCollection>("SELECT LZoneNum from dbo.LZLinks WHERE Device = @DeviceID", DevItem);
    BindingSource LZluBinding = new BindingSource();

    //nlzcol contains the Zones already subscribed

    object[] lzsubs = new object[nlzcol.Count];
    int i = 0;
    foreach (object o in nlzcol)
    {
          lzsubs = nlzcol.LZoneNum;
          i++;
    }
    Orion.
    LZoneCollection lzc = Orion.DB.Select().From<Orion.LZone>().Where("LZoneNum").NotIn(lzsubs)
    .ExecuteAsCollection<Orion.
    LZoneCollection>();

    ////This blows up look at it later
    // List<LZLookup> lzlu = SPs.NotInLzonesForDevice(6)
    // .ExecuteTypedList<LZLookup>();

    LZluBinding.DataSource = lzc;
    gvLZLookup.DataSource = LZluBinding;
    //// Now The Data Table
    gvLZSub.DataSource = LZoneBinding;

    hth dan

     

     

     

    If you're going to look back and laugh... You might as well laugh now!

  • 05-23-2008 4:21 PM In reply to

    • del
    • Top 500 Contributor
    • Joined on 03-03-2008
    • Posts 10

    Re: Wheres and NOT IN

    I forgot about the query factory option, using that I got it to work.  The implementation of NOT_IN must be different than NotIn.  I was using an ArrayList for inList, but did not try an object array.

    Doesn't work:

    qry = new Query(MathcadValue.Schema).NOT_IN("Id", inList);

    mvColl.LoadAndCloseReader(qry.ExecuteReader());  //errors wiith 'Must declare the scalar variable "@notIn1"'

     

    Does work:

    mvColl = DB.Select().From("MathcadValue").Where("Id").NotIn(inList).ExecuteAsCollection<MathcadValueCollection>();

     

    Thanks

Page 1 of 1 (4 items) | RSS