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
Writing to Output Window of Visual Studio
How to Force Bundlecollection to Flush Cached Script Bundles in MVC4
Should the Repository Layer Return Data-Transfer-Objects (Dto)
Working with C# Anonymous Types
Sending Sms from an ASP.NET Website
Automatic Cookie Handling C#/.Net Httpwebrequest+Httpwebresponse
Total Number of Items Defined in an Enum
Dispatcher Invoke(...) VS Begininvoke(...) Confusion
Extract Thumbnail for Any File in Windows
Where Is Httpcontent.Readasasync
Creating Threads - Task.Factory.Startnew VS New Thread()
Why Is There a Difference in Checking Null Against a Value in Vb.Net and C#
Difference Between Destructor, Dispose and Finalize Method
How to Compare Lists in Unit Testing
ASP.NET Identity Cookie Across Subdomains
C# Code for Association, Aggregation, Composition
Threadstatic V.S. Threadlocal<T>: Is Generic Better Than Attribute