Cannot Convert Lambda Expression to Type 'String' Because It Is Not a Delegate Type

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

I think you are missing using System.Linq; from this system class.

and also add using System.Data.Entity; to the code

C# Linq with MVC, Cannot convert lambda expression to type 'string' because it is not a delegate type

try changing @Html.DisplayName(model => model.itemnum) to @Html.DisplayNameFor(model => model[0].itemnum).
you need DisplayNameFor to use an expression, DisplayName just displays a string.

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

The Include method expects a string, not a lambda:

public ViewResult List()
{
var sites = context.CustomerSites.Include("Customer");
return View(sites.ToList());
}

Of course you could write a custom extension method which would work with lambda expressions and make your code independant of some magic strings and refactor friendlier.

But whatever you do PLEASE OH PLEASE don't pass EF autogenerated objects to your views. USE VIEW MODELS.

Cannot convert lambda expression to type 'string' because it is not a delegate type - OrderBy and DbGeography by ref

The error you get is caused by funny things the overload resolution of C# is doing... It is trying to resolve your OrderBy to the Dynamic Linq "version" of OrderBy, that accepts a string as a parameter.

In general, a more correct error, and the one you get if you remove the using System.Linq.Dynamic; or if you rewrite the statement to force using Queryable.OrderBy, like:

var query = Queryable.OrderBy( this.context.Fields.Where( x => x.DeletedAt == null ),
x => x.GeoLocation.Distance( geo ) );

would be Cannot use ref or out parameter 'geo' inside an anonymous method, lambda expression, or query expression. As pointed by rdoubleui, here there is an explanation for that.



Related Topics



Leave a reply



Submit