locked
Select rows without joining other tables regarding other tables RRS feed

  • Question

  • User247803987 posted

    I'm working in asp.net web forms 4.5 version.

    I have trouble with linq. I want to bring a table data.. (I don't want to join it.. as I would want it to be deleted and edited by the autodelete and autoedit button of gridview)

    But I'm lost with linq.

    I would like to do something like this..

    public Iqueryable detailGrid_getData(){
        string fromDStr = fromTBox.Text;
        DateTime fromD = Convert.ToDateTime(fromDStr);
    
        string toDStr = toTBox.Text;
        DateTime toD = Convert.ToDateTime(toDStr);
    
        var items = from s in db.salesOrderDetail_T where 
        db.salesOrder_T
        .Select(so => so.poDate <= toD && so.poDate >=fromD)
        .Contatins(s.soIdx) && s.stat == stat;
        return items;
    }

    at which I got the idea from here : LINQ, select ID from Table where it does not match ID in another table

    but for some reason, it doesn't work. Will someone tell me why this is not working??

    edit : It says a query body must end with a select clause or a group clause

    Wednesday, December 20, 2017 2:29 PM

All replies

  • User1400794712 posted

    Hi jimmythegreat,

    Just like what the error message said, you need to add select/group after the query, for example:

    var items = from s in db.salesOrderDetail_T where 
        db.salesOrder_T
        .Select(so => so.poDate <= toD && so.poDate >=fromD)
        .Contatins(s.soIdx) && s.stat == stat
        select s;

    Then inside the Select(), there should be the property of salesOrder_T, not bool. 

    As my guessing of your need, the code can be:

    var items = from s in db.salesOrderDetail_T where 
        db.salesOrder_T
        .Where(so => so.poDate <= toD && so.poDate >=fromD)
        .Select(so=>so.XXX)//The property which is simiar to s.soIdx
        .Contatins(s.soIdx) && s.stat == stat
        select s;

    If you have any confusion, please give more details about your need.

     

    Best Regards,

    Daisy

    Monday, December 25, 2017 7:34 AM