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


  • I am feeling very lost at the moment and cannot figure out why I am getting this error. I am trying to do a simple LINQ to EF to get the Customer by CustomerID from the AdventureWorksLT database. I have the Customer, CustomerAddress and Address tables in my model.


    BTW, I do not get this error in VB with the same model and LINQ statement.


    int CustomerId = int.Parse(Request.QueryString["CustomerId"]);
    Customers vCustomer;

    vCustomer = (from c in ctx.Customers
     where c.CustomerID == CustomerId
     select c).First();

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

    Thursday, August 21, 2008 1:23 PM


All replies

  • What line in your code does this error reference?


    Thursday, August 21, 2008 8:38 PM
  • It is giving me the error on the 'where'.


    Thursday, August 21, 2008 9:10 PM

    using System.Linq;

    Sunday, September 28, 2008 12:02 AM
  • Thanks. Adding the using line worked for me.

    The use of extensions is great but produces some headache on compiler errors....
    Wednesday, December 03, 2008 3:50 PM
  • i have the same error but the error is in the select, i already use "using System.Linq"

    var test = from o in order.Include("Customers")

     select new { o.OrderID,

    (from c in o.Customers select c.CustomerID).toArray };

    • Proposed as answer by narayanann Monday, January 19, 2009 11:41 AM
    Friday, December 05, 2008 2:31 AM
  • You rock.  That was the one.
    Thursday, May 27, 2010 1:28 AM
  • Thanks. Adding the using System.Linq; line works.
    Monday, June 07, 2010 9:51 PM
  • Thank you Thank you!  Adding the using to my unit test did the trick.


    Friday, November 19, 2010 10:07 PM
  • great! worked...



    Saturday, January 29, 2011 1:18 AM
  • In C# you have to add a reference to "System.Data.DataSetExtensions" in the projects properties.
    Then make sure you have using statements for System.Data and System.Linq.
    You must use the AsEnumerable() extension of the DataTable type, as below:

    // use LINQ to get a generic List of custom objects
    List<MyObject> myList = (from c in MyDataTable.AsEnumerable()
                                               select new MyObject
                                                    MyObjectProperty = c.Field<int>("ColumnName1"),
                                                    MyObjectProperty = c.Field<string>("ColumnName2")

    • Proposed as answer by Vasan JS Tuesday, November 08, 2011 10:53 AM
    Wednesday, March 09, 2011 4:53 PM
  • Yes it worked. Can't get much more elegant than that.
    Adam Bruss
    Tuesday, March 29, 2011 7:51 PM
  • This one gets people over and over and over.  It's like a timeless classic, in a not so fun way.

    Jamie Miley
    Check out my profile!
    Linked-In Profile
    Follow Me on Twitter!
    Saturday, July 16, 2011 3:27 AM

  • Yes ! thanks ! Microsoft tells things in the easy way as always... You saved my day.
    Thursday, August 30, 2012 12:52 PM
  • I am experiencing the same issue but i am using VB.NET and am already using the "Imports System.Linq" but it's still reporting issue. 

    I am using VB.NET with MVC 3.

    This is the code

      If Not String.IsNullOrEmpty(bindingContext.ModelName) AndAlso Not bindingContext.ValueProvider.ContainsPrefix(Function(s) s.StartsWith(bindingContext.ModelName)) Then

                    'this should only be true for top level objects
                    If Not bindingContext.FallbackToEmptyPrefix Then
                        Return Nothing
                    End If

                    bindingContext = New ModelBindingContext() With { _
                     .Model = bindingContext.Model, _
                     .ModelState = bindingContext.ModelState, _
                     .ModelType = bindingContext.ModelType, _
                     .PropertyFilter = bindingContext.PropertyFilter, _
                     .ValueProvider = bindingContext.ValueProvider _
                End If

    Please help

    Monday, September 10, 2012 3:49 AM
  • Maybe try Imports System.Data.Entity (VB) / using System.Data.Entity; (C#)
    • Proposed as answer by Ace supriatna Tuesday, May 27, 2014 10:46 AM
    Thursday, December 13, 2012 6:04 AM
  • I got this error where referencing System.Linq didn't help in an MVC Razor view.

    column.For( i => i.Start_time.HasValue ? i.Start_time.ToString( "dd-MM-yyyy" ) : empty ).Named( "Incident Date" );

    So using a nullable DateTime in a lambda expression, I'd forgotten of course to reference the Nullables value:

    column.For( i => i.Start_time.HasValue ? i.Start_time.Value.ToString( "dd-MM-yyyy" ) : empty ).Named( "Incident Date" );

    Tuesday, January 15, 2013 10:27 AM