Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# displaying error 'Delegate 'System.Func<...>' does not take 1 arguments

I am calling:

        form = new FormFor<Project>()
            .Set(x => x.Name, "hi");

where Project has a field called Name and FormFor's code is:

public class FormFor<TEntity> where TEntity : class
{
    FormCollection form;


    public FormFor()
    {
        form = new FormCollection();
    }

    public FormFor<TEntity> Set(Expression<Func<TEntity>> property, string value)
    {
        form.Add(property.PropertyName(), value);

        return this;
    }
}

but it keeps telling me Delegate 'System.Func<ProjectSupport.Core.Domain.Project>' does not take 1 arguments and I am unsure why. Could anyone shed some light on it for me?

like image 795
Harold Avatar asked Mar 02 '11 13:03

Harold


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


1 Answers

It's trying to convert this lambda expression:

x => x.Name

into an Expression<Func<TEntity>>.

Let's ignore the expression tree bit for the moment - the delegate type Func<TEntity> represents a delegate which takes no arguments, and returns a TEntity. Your lambda expression x => x.Name clearly is expecting a parameter (x). I suspect you want

Expression<Func<TEntity, string>>

or something similar, but it's not really clear what you're trying to do.

like image 189
Jon Skeet Avatar answered Sep 21 '22 17:09

Jon Skeet