0

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

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Jinmo Chong
  • 91
  • 1
  • 12
  • How, exactly is it not working? Can you replace your code with code that will at least compile? Right now, it is illegal. Some sample problems - missing semicolon, using `Select` to create an IEnumerable of `Boolean`, using `.Contains` on a `IEnumerable` without a boolean search object (I assume `s.soIdx` is not a boolean, using comprehension query syntax without ending with a select clause. – NetMage Dec 19 '17 at 22:25
  • 1
    I'd recommend breaking the problem up - first try to query the data using [LINQPad](https://www.linqpad.net/) or a console app (eliminating ASP.NET from the equation) and see if that works. See also https://stackoverflow.com/help/mcve – TrueWill Dec 19 '17 at 22:26

2 Answers2

0

The error message is quite clear here. Your query (items) does not end in a select clause, I think this is what you want:

var items = from s in db.salesOrderDetail_T where 
            db.salesOrder_T.Where(so => so.poDate <= toD && so.poDate >=fromD).Select(p=>p.Id).Contains(s.soIdx) 
            && s.stat == stat
            select s;
flipside
  • 81
  • 1
  • 5
  • It says 'System.Linq.IQueryable' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.ParallelEnumerable.Contains(System.Linq.ParallelQuery, TSource)' has some invalid arguments and I have no idea what this means. – Jinmo Chong Dec 21 '17 at 14:35
  • Sorry didn't check the rest of your query. I've moved your boolean statement into a where clause and select the salesOrder_T id for comparison. – flipside Dec 21 '17 at 15:22
0

I would like to answer this because I figured it out totally different way. Turns out that in LINQ, I can get around things in a lot of way.

This is the way I got through this.. Still not that expert in LINQ, but getting it.

var items = from so in db.salesOrderDetail_T
    where so.poDate <= toD && so.poDate >= fromD
    select so.idx;
soIdxList = items.toList();
items = items.Where(it => soIdxList.Contains((int) it.soIdx)

and then, use it. Again, I'm not sure this is a good way to do things, but it's easy and works.

Jinmo Chong
  • 91
  • 1
  • 12