Hi. I'm a newbie in the great world of NHibernate. I'm using version 2.0.1.GA. Here's my question. I have a table Cars with column Manufacturer(nvarchar(50)) and a primary key ID(int). My .NET class is:
public class Car
{
public virtual int ID { get; set; }
public virtual string Manufacturer { get; set; }
}
Now if I want to re...
Are there C++ compilers already supporting C++0x lambda expressions?
...
I have the following Transact-Sql that I am trying to convert to LINQ ... and struggling.
SELECT * FROM Project
WHERE Project.ProjectId IN (SELECT ProjectId FROM ProjectMember Where MemberId = 'a45bd16d-9be0-421b-b5bf-143d334c8155')
Any help would be greatly appreciated ... I would like to do it with Lambda expressions, if possible....
Has anyone an idea how the type inference problem
E > hd (cons 1 nil) : α0
with the typing environment
E={
hd : list(α1 ) → α1 ,
cons : α2 → list(α2 ) → list(α2 ),
nil : list(α3 ),
1 : int
}
can be transferred in an unificat...
In C#, I'm trying to build an extension method for StringBuilder called AppendCollection() that would let me do this:
var sb1 = new StringBuilder();
var sb2 = new StringBuilder();
var people = new List<Person>() { ...init people here... };
var orders = new List<Orders>() { ...init orders here... };
sb1.AppendCollection(people, p => p.T...
There must be an easy way to do this, but somehow I can wrap my head around it. The best way I can describe what I want is a lambda function for a class. I have a library that expects as an argument an uninstantiated version of a class to work with. It then instantiates the class itself to work on. The problem is that I'd like to be able...
Pour in your posts. I'll start with a couple, let us see how much we can collect.
To provide inline event handlers like
button.Click += (sender,args) =>
{
};
To find items in a collection
var dogs= animals.Where(animal => animal.Type == "dog");
For iterating a collection, like
animals.ForEach(animal=>Console.WriteLine(animal.Na...
Is is possible to have a local variable in an anonymous c# methods, i.e. in the following code I would like to perform the count only once.
IQueryable<Enquiry> linq = db.Enquiries;
if(...) linq = linq.Where(...);
if(...) linq = linq.Where(e =>
(x <= (from p in db.Orders where p.EnquiryId == e.Id select p).Count() &&
(fro...
I am fairly new to programming and while doing a lot of reading this concept of a lambda keeps coming up but I'm having a hard time putting my finger on what it actually is and how implementing it will make my programming life so much better. So first, what is a lambda and second how might it be implemented?
Thanks to all who posted. ...
I would like to be able to refactor out the OrderBy clause in a linq expression.
Here is an example of a refactor of the where clause
before:
results = ctx.ActiveUsers
.Where(u => u.CompanyID != 1 &&
(u.LastName.ToLower().Contains(searchString)
|| u.Email.ToLower().Contains(searchString)
|| u.Co...
I my last question about haskell, the answer provided gave me another doubt... Instead of using the somewhat complex function in my other question, here's a simpler example:
sumAll :: [(Int,Int)] -> Int
sumAll xs = foldr (+) 0 (map f xs)
where f (x,y) = x+y
Calling sumAll [(1,1),(2,2),(3,3)] the output will be 12.
What I don't unde...
Lambda syntax in C# 3 makes it really convenient to create one-liner anonymous methods. They're a definite improvement over the wordier anonymous delegate syntax that C# 2 gave us. The convenience of lambdas, however, brings with it a temptation to use them in places where we don't necessarily need the functional programming semantics ...
How are anonymous functions/lambda expressions expressed in various programming languages? Are the syntax and semantics especially useful or not useful in that language? Are there any programming languages for which true anonymous functions aren't possible?
Like other Rosetta Stone questions, responses should start with the name of th...
Hello,
I recently upgraded a Web Application Project (as well as some dependent projects) from .net 2.0 to .net 3.5 using the built in conversion tool. Everything works well such as using MS AJAX 3.5 vs. the external MS AJAX libraries in 2.0.
My problem occurs when I tried using the new Lambda Expression syntax. The compiler will not r...
I found the following rather strange. Then again, I have mostly used closures in dynamic languages which shouldn't be suspectable to the same "bug". The following makes the compiler unhappy:
VoidFunction t = delegate { int i = 0; };
int i = 1;
It says:
A local variable named 'i' cannot be
declared in this scope because it
wou...
Given a method DoSomething that takes a (parameterless) function and handles it in some way. Is there a better way to create the "overloads" for functions with parameters than the snippet below?
public static TResult DoSomething<TResult>(Func<TResult> func)
{
//call func() and do something else
}
public static TResult DoSomething<T...
Take the method System.Windows.Forms.Control.Invoke(Delegate method)
Why does this give a compile time error:
string str = "woop";
Invoke(() => this.Text = str);
// Error: Cannot convert lambda expression to type 'System.Delegate'
// because it is not a delegate type
Yet this works fine:
string str = "woop";
Invoke((Action)(() => th...
One advantage of lamda expressions is that you only have to evaluate a function, when you need its result.
In the following (simple) example, the text function is only evaluated when a writer is present:
public static void PrintLine(Func<string> text, TextWriter writer)
{
if (writer != null)
{
writer.WriteLine(text());
...
I'm starting to love Lambda expressions but I'm struggling to pass this wall:
public class CompanyWithEmployees
{
public CompanyWithEmployees() { }
public Company CompanyInfo { get; set; }
public List<Person> Employees { get; set; }
}
My search:
List<CompanyWithEmployees> companiesWithEmployees = ws.GetCompaniesWithEmploy...
Just a general question about what the best practice is:
public void Foo()
{
int x = 5;
myControl.Click += (o, e) =>
{
x = 6;
};
}
Notice, I'm using the x variable inside my lambda event handler.
OR:
public class Bar
{
private ...