I meant id <= 123, indeed.
If you have different conditions, and if you can write queries, I suggest
to use an ad hoc query rather than using a more general query which cpuld
be poorly optimized. Sure, making a specific query each time implies that
the query plan will have to be evaluated, but that is generally very
fast.
The Select( (p,i) => ... ) syntax is from LINQ to object:
var myData=new []{new {id=11, who="hello"}, new{ id=17,
who="oz"} , new {id=22, who="bye"}};
var toto = myData.Select((p, i) => new { p.id, p.who, position
=i });
var jojo = toto.Where(q => q.who == "bye").Select(z =>
z.position);
int k = jojo.ToList()[0];
System.Diagnostics.Debug.Assert(k == 2);
Note that you can append where clause. Here, I added a WHERE clause
BETWEEN two SELECT clauses and while I did it in two steps, it could have
been done in just one:
int kk = myData.Select((p, i) => new { p.id, p.who, position =
i })
.Where(q => q.who == "bye").Where(q => q.id == 22).Select(z
=> z.position)
.ToList()[0];
where I even add a second WHERE clause to show the concept of building
successively additional conditions.
Vanderghast, Access MVP
Andrus said:
and I doubt it is supported in LINQ, so you should expand the criteria
to:
WHERE location <> 'GB' and (CustomerName <= 'Airbus' OR (CustomerName =
'Airbus' AND id= 123));
For multiple customers with name Airbus this causes incorrect result.
Did you mean AND id<= 123 ? :
WHERE location <> 'GB' and (CustomerName <= 'Airbus' OR (CustomerName =
'Airbus' AND id<= 123));
Sometimes I have 4-5 order keys.
Should I create query condition manually for all cases or is it possible
to create some method which creates new query expression tree
automatically
from original query Where and Order By expression trees ?
Alternatively, you can loop until you find the desired record, or try
to
use the method Select( (p, i) => i )
where i is the index position of the record, supplied for you, by the
system (though I personally failed to get something useful from it, for
THIS case).
How I can get position of the record from system ?
Sql served do not have such function as I know.
I need to show this record in WinForms DataGridView using local mode.
The alternative way should be to force virtualmode DataGridView to show
neighbour records by given id. However I have no idea is this possible
or
not.
Andrus.