Cannot convert lambda expression to type "string" because it is not a delegate type

I use the lambda LINQ expression as follows:

int Value = 1; qryContent objContentLine; using (Entities db = new Entities()) { objContentLine = (from q in db.qryContents where q.LineID == Value orderby q.RowID descending select q).FirstOrDefault(); } 

However, I get the following error:

Cannot convert lambda expression to input 'string' because it is not a delegate type

+67
c # lambda linq
05 Oct '13 at 11:51
source share
5 answers

I think that in this system class is missing using System.Linq; .

as well as add System.Data.Entity; into code

+170
Oct 05 '13 at 12:00
source share

In my case, I had to add using System.Data.Entity;

+90
Dec 06 '13 at 7:26
source share

In my case, he decided to use

 @Html.DropDownList(model => model.TypeId ...) 

using

 @Html.DropDownListFor(model => model.TypeId ...) 

will solve it

+7
Nov 11 '14 at 7:27
source share

If this is not due to the lack of directives declared by other users, this will also happen if there is another problem with your request.

Look at the VS compiler error list: For example, if the "Value" variable in your request does not exist, you will have a "lambda-string" error, and several errors after another are still associated with an unknown / erroneous field.

In your case, it could be:

 objContentLine = (from q in db.qryContents where q.LineID == Value orderby q.RowID descending select q).FirstOrDefault(); 

Errors:

Error 241: Cannot convert lambda expression to type 'string' because it is not a delegate type

Error 242 The delegate 'System.Func <..>' does not accept 1 argument

Error 243 The name "Value" does not exist in the current context

Correct the variable variable "Value" and other errors will also disappear.

+4
Jan 15 '15 at 15:02
source share

For people who are just stumbling about it now, I solved an error of the type that was selected with all the links and used the correct positions. Obviously, there is some confusion with replacing a function that returns a DataTable, rather than calling it in a declared DataTable. For example:

This worked for me:

 DataTable dt = SomeObject.ReturnsDataTable(); List<string> ls = dt.AsEnumerable().Select(dr => dr["name"].ToString()).ToList<string>(); 

But that did not happen:

 List<string> ls = SomeObject.ReturnsDataTable().AsEnumerable().Select(dr => dr["name"].ToString()).ToList<string>(); 

I'm still not 100% sure, but if someone is disappointed with a mistake of this type, try this.

+2
Jul 24 '14 at 14:31
source share



All Articles