How to convert LINQ query to Lambda automatically - linqpad

I am curious to know how to convert LINQ query to lambda so I visited the below link and follow the same but my linq query could not convert to lamda automatically.
convert this LINQ expression into Lambda
This is my LINQ pad image where I use C# program:
Can anyone guide me what I am doing for which linq pad not being able to convert my linq to lambda?

You're not in "C# Expression" mode. Copy and paste just the LINQ part (from x in y...) to a new tab (make sure C# Expression is selected from the droplist) and then try converting to lambda. Repeat for other LINQ query.

i found out how to do it. here is the screen shot.
Writing the Query expression directly without .ToList(), .FirstOrDefault(), SingleOrDefault() will show the coresponding Lambda Expression in Lambda ExpressionTab.

Related

is this a Sql query or linq

any one know what kind of query is this??
var r = dc.user_details.Where(a => a.username.Equals(u.username) && a.passkey.Equals(u.passkey)).FirstOrDefault();
It is LINQ query. (The Enumerable methods are part of system.linq namespace)
The method "where" is part of "Enumerable Methods".
https://msdn.microsoft.com/en-us/library/system.linq.enumerable_methods(v=vs.110).aspx
Inside "Where" the predicate is a lamda expression. (This is a C# programming concept. Not part of LINQ)
https://msdn.microsoft.com/en-us/library/bb397687.aspx
Again the "FirstOrDefault" is a "Enumerable method", You can find it in the first link.
These are an extension methods that achieves the same as LINQ. It is another way for writing LINQ queries.
This is a linq query which checks the username and passkey and gives the result weather the user name and passkey exist in the table or not.

Nhibernate : QueryOver equivalent for ICriteria's SetComment?

Is is possible to add a comment to generated by queryover query in Visual Studio's output?
Previously when we were using ICriteria, there was simple SetComment method and we could set the query name so it was much easier to find specific query in output full of long (almost the same) queries. If it is possible we would prefere to add such comments without converting query to ICriteria.
I don't think there is a direct way of doinf it, but you can try with:
QueryOver<Entity>()
.Where(...
.UnderlyingCriteria.SetComment("....")

Transforming SQL into Linq To Objects expressions at runtime

Does anyone know of any libraries that one can use to parse a SQL query and build up a linq expression which can then be compiled and used against linq to objects?
This approach only needs to work for simple queries, for complex ones I can write a hardcoded custom query
UPDATE: I've found something called NQuery which should do the trick for me http://nquery.codeplex.com/ so don't waste your time answering!
There is a project call [SqlLinq] (https://github.com/dkackman/SqlLinq) which converts SQL into c# Expression Trees, and evaluates them.

load record by predicate/lambda via vb.net linq

im pretty confused about lambdas and actually im not even sure i need them here
what im trying to do here is write a function that will return an object from a certain table with a certain criteria
so lets say i can write
function GetRecord(TableName as string,Criteria as string) as object
'do the linq-stuff
end function
now i dont care if the paremeters are strings or lambdas or whatever, but the end result must be that at runtime i dont know which table and which criteria will be used
as sometimes i need to get a customer record by email and sometimes a product by id etc.
if possible i would prefer returning a list of matching objects and then i would just use .firstordefault when i want 1 (such as by id...)
thank you , as always, for taking the time to read this and answer!
all the best
Have you considered using Dynamic LINQ?
Example:
Parsing an expression tree can be a challenging but rewarding method of solving this issue. I think it's overkill and I'd go with Dynamic Linq as decyclone mentioned.
A benefit of parsing the expression tree, however, is that you can have compile time checking of the submitted criteria.
Here are some articles that helped me.
How to: Implement an Expression Tree Visitor: http://msdn.microsoft.com/en-us/library/bb882521(VS.90).aspx
Building a custom IQueryable Provider: http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx
Walkthrough: Creating an IQueryable LINQ Provider: http://msdn.microsoft.com/en-us/library/bb546158(v=VS.90).aspx
Expression Tree Basics:
http://blogs.msdn.com/b/charlie/archive/2008/01/31/expression-tree-basics.aspx

Linq to nhibernate string comparison

I have a question on linq to nhibernate. I need to create a query in which I could use string comparison:
session.Linq<User>()
.Where(u => String.Compare(u.Name, givenName) < 0)
.ToList()
Do I understand correctly that this is not supported in linq-to-nhibernate? Is there a way to use string comparison in linq-to-nhibernate?
The new integrated provider in NHibernate 3 allows extending it to support pretty much any construct you want.
Check http://fabiomaulo.blogspot.com/2010/07/nhibernate-linq-provider-extension.html for a full example.
Of course, you'll need to think of a reasonable HQL representation of that expression.
This is no longer needed. The lambda expression in the question is now supported.