Error. Cannot convert lambda expression to type 'int' because it is not a delegate type

This is the source code (I am using CodeSmith tools):

public static int Delete(this System.Data.Linq.Table<EAccredidation.Data.Programs> table, int pKProgramID)
{
    return table.Delete(p => p.PKProgramID == pKProgramID);
}

I get this error:

Cannot convert lambda expression to type 'int' because it is not a delegate type C: \ Projects \ New \ EAccreditation.Data \ Queries \ ProgramsExtensions.Generated.cs

How can i fix this?

+5
source share
2 answers

You specified your method as an extension method, so for the purposes of your example, you can ignore the first parameter in the method declaration.

Consequently, the only parameter to which you are connected, is the second int pKProgramID.

When you call this method (recuirsively), it expects an int, but you pass the lambda delegate ( p => p.PKProgramID == pKProgramID)

, , , !

+6

. :

table.DeleteAllOnSubmit(table.Where(p => p.PKProgramID == pKProgramID));

, , PK :

var record = table.SingleOrDefault(p => p.PKProgramID == pKProgramID);
if(record != null) table.DeleteOnSubmit(record);

, , SubmitChanges() - .

0

All Articles