Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am using this code in mvc for delete.

C#
public ActionResult Delete()
        {
            string StudentId = Request.QueryString["stuId"].ToString();
            Book_DBEntities objentity = new Book_DBEntities();
            studentdetail objstudentdetail = new studentdetail();
            objstudentdetail = (from data in objentity.studentdetails
                                where data.studentid = StudentId 
                                select data).FirstOrDefault();
            StudentList _objstudentlist = new StudentList();
            _objstudentlist.Id = StudentId;
            _objstudentlist.Name = objstudentdetail.Name;
            _objstudentlist.Address = objstudentdetail.Address;
            _objstudentlist.Marks = (int)objstudentdetail.Marks;
            _objstudentlist.Section = objstudentdetail.Section;
            StudentListModel objstudentlistmodel = new StudentListModel();
            objstudentlistmodel.StudentListDetail = _objstudentlist;
            return View(objstudentlistmodel);
            
        }

but it's showing error in
where data.studentid = StudentId
this line.

Error: Delegate 'System.Func<studentinformation.studentdetail,int,bool>' does not take 1 arguments.

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

Cannot implicit convert type 'string' to bool.

These three errors are giving.

How i resolve this error?
Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Updated 9-Nov-14 22:41pm
v2

Try a double == :
C#
objstudentdetail = (from data in objentity.studentdetails
where data.studentid == StudentId
select data).FirstOrDefault();
 
Share this answer
 
Comments
[no name] 10-Nov-14 4:39am    
Thanks, I have missed the double ==.
Maciej Los 10-Nov-14 4:44am    
+5
Mehdi Gholam 10-Nov-14 5:38am    
:)
Um.
Try "==" instead of "="?
C#
where data.studentid = StudentId
Becomes
C#
where data.studentid == StudentId
 
Share this answer
 
Comments
Garth J Lancaster 10-Nov-14 4:42am    
and here I was tidying up the question and you both jump in and answer it - sheesh :-)
The above error mentioned:-
Quote:
Cannot convert lambda expression to type 'string' because it is not a delegate type

This error comes sometimes when you have missed the namespace for linq
using System.Linq; or using System.Data.Entity;
Mehdi and Griff are absolutely correct that you have missed out double equals, please just keep in mind and check for the namespaces also. Sometimes the double equals also throws the first error you have mentioned because of the namespaces.
Hope this helps anyway.
Thanks.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900