Re: convert query to DLinq

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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" <kobruleht2@xxxxxx> wrote in message news:e1hP8gs2IHA.5728@xxxxxxxxxxxxxxxxxxxxxxx
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.

.



Relevant Pages

  • RE: Any good T-SQL quick reference recommended?
    ... The full syntax of the SELECT ... SELECT Clause ... Specifies the columns to be returned by the query. ... Specifies that duplicate rows can appear in the result set. ...
    (microsoft.public.sqlserver.programming)
  • RE: Xlocking with a select statement
    ... named query expression, order clause, update clause, lock option ... A result table or the underlying base tables are updateable if the query ... A lock can be requested for the ...
    (microsoft.public.sqlserver.programming)
  • Re: update query: still having problems
    ... "Michel Walsh" wrote: ... From the User Interface, in the toolbar, or the menu, when you edit a query, ... If this is what you want, fine, else, add a WHERE clause to limit ... SELECT Department.*, sheet1.* ...
    (microsoft.public.access.queries)
  • Re: update query: still having problems
    ... "Michel Walsh" wrote: ... you should find a button that allows you to change the query "type". ... If this is what you want, fine, else, add a WHERE clause to ... SELECT Department.*, sheet1.* ...
    (microsoft.public.access.queries)
  • Re: VB-ADO-SQL Server : SQL Server performs logins after some queries
    ... If you have some joins or WHERE clause in your statement, ... Also try to minimize selection of the records using WHERE ... Incase of actual action query, ... >> of queries and I've concluded that in case of an internet conection the ...
    (microsoft.public.vb.database.ado)