linq-to-sql delegate does not take "1" argument

Answered linq-to-sql delegate does not take "1" argument

  • Monday, August 04, 2008 3:22 AM
     
     

    I try to select record from customer id which starts with A but i got this error:

     

    • Delegate 'System.Func<Customers,int,bool>' does not take '1' arguments.

     

     

    NORTHWINDEF db = new NORTHWINDEF("Integrated Security=sspi");

    var products = from p in db.Customers

    where p.CustomerID.StartsWith("A")           < --

    select p;

     

    listBox1.Items.Add(products);

All Replies

  • Monday, August 04, 2008 7:37 PM
     
     

    I am not able to reproduce your issue. Is the NORTHWINDEF a LINQ to SQL context?

     

    Jim Wooley

    www.ThinqLinq.com

     

  • Thursday, August 07, 2008 3:19 AM
     
     Answered

    Hi learner08,


    I have tried to test this code snippet in a LINQ to SQL sample, it works fine, please check the code snippet below.


    string connectionString = @"Data Source=server-name;database=Northwind;Integrated Security=True;";

                     using (SqlConnection connection = new SqlConnection(connectionString))

                     {

                         connection.Open();

                         NorthWindDataContext db = new NorthWindDataContext(connection);

     

                         var queryResult = from s in db.Customers

                                           where s.CustomerID.StartsWith("V")

                                           select s;

                      }


    So I believe there is no error in your above code snippet, perhaps the error is in other code, just review your code closely, or post some of them which probably cause the error.


    Regards,

    Xun

  • Thursday, August 07, 2008 3:27 AM
     
     

    good to hear from you, but my project planned to use entity framework and i use linq-to-entities such as below, with edmx setup:

     

     

    private Project1NTBackupEntities CClientContext;

     

    CClientContext = new Project1NTBackupEntities();

    cclist cc1 = CClientContext.cclist.Where("it.computername = @computername",

    new ObjectParameter("computername", ln)).First();

     

     

    before this, i worked on sqlconnection, however i got the error at connection.Open() < --- does not allow remote connection, i try to configure sql server with enabling the remote, still does not work.

  • Thursday, August 07, 2008 3:31 AM
     
     

    Hi ,

    Sorry, I am not familiar with LINQ to entity, but you can refer to the following forum which concerns this question.

    ADO.NET Entity Framework and LINQ to Entities (Pre-release)


  • Thursday, August 07, 2008 3:36 AM
     
     

    i got one question,

     

    NorthWindDataContext db = new NorthWindDataContext(connection);

     

    where and how did u declare the NorthWindDataContext? (im using VS2008)

     

  • Thursday, August 07, 2008 3:43 AM
     
     

    Hi learner08,


    Well, “NorthWindDataContext” is a LINQ to SQL class, and I generate it by doing the following steps.


    1.       Add “LINQ to SQL class” item to the project, named it “NorthWind.dbml”

    2.       Open the DBML file in the design view, drag and drop the tables of “Northwind” database from the Server explorer to the DBML file.


    And there is a LINQ to SQL class generator tool as well, which is Code Generation Tool (SqlMetal.exe)


    Regards,

    Xun

     

  • Thursday, August 07, 2008 4:05 AM
     
     

    i got the class from dbml file already, but i also have this in my app.config:

     

    <connectionStrings>

    <add name="LinqToSQL1.Properties.Settings.NorthwindEFConnectionString"

    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NorthwindEF.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

    providerName="System.Data.SqlClient" />

    </connectionStrings>

     

    how do i put it in my code to shorten the connection string:

     

    string connectionString1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NorthwindEF.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;";

    using (SqlConnection connection = new SqlConnection(connectionString))

    {

    connection.Open();

    NorthWindDataContext db1 = new NorthWindDataContext(connection);

     

    var queryResult = from s in db1.Customers

    where s.CustomerID.StartsWith("A")

    select s;

    dataGridView1.DataSource = queryResult;

    connection.Close();

    }

     

    the datagridview1 shows empty ...

  • Thursday, August 07, 2008 4:12 AM
     
     

    Hi,

    Would you please create a new thread to ask your new question, in general, one thread just for one question.

    Regards,
    Xun
  • Wednesday, May 18, 2011 2:53 PM
     
     

    Replying for others who may encounter the original issue, "Delegate 'System.Func<Customers,int,bool> does not take '1' arguments':

    I recently encountered this issue with Linq to Entities after I had changed a fieldname in my underlying table and refreshed my entity model.  The linq query I had selecting from my ObjectContext still used the old fieldname in the query (i.e. .Where(x => x.OldFieldname == "MyValue").  I got the above error ('Delegate '<mytype>,int,bool> does not take '1' arguments' until I fixed the fieldname.

    • Proposed As Answer by ronenfe Wednesday, August 03, 2011 12:06 PM
    • Unproposed As Answer by ronenfe Wednesday, August 03, 2011 12:08 PM
    •  
  • Saturday, February 11, 2012 7:19 AM
     
     

    Found at http://mytechsolutions.blogspot.com/2011/11

    If you get the error Delegate 'System.Func<entityName,int,bool>' does not take 1 arguments
    or
    Cannot convert lambda expression to type 'string' because it is not a delegate type
    then check the linq query and confirm that the "where" condition has == instead of = .. 
    var allProducts = from p in context.Products where p.productID == 1 select p;

  • Friday, August 10, 2012 1:10 PM
     
     
    I had an error like this, Visual Studio was telling me there was an error.  I had just added the table to my dbml.  I tried building it, and the error went away.