如何解决无法将lambda表达式转换为类型'string',因为它不是委托类型。错误。? [英] How to resolve Cannot convert lambda expression to type 'string' because it is not a delegate type. Error.?

查看:921
本文介绍了如何解决无法将lambda表达式转换为类型'string',因为它不是委托类型。错误。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在mvc中使用此代码进行删除。



  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
其中​​ data.studentid = StudentId
选择数据).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 查看(objstudentlistmodel);

}



但它显示错误

其中data.studentid = StudentId

这一行。



错误:委托'System.Func< studentinformation.studentdetail,int,bool>'不带1个参数。



无法将lambda表达式转换为'string'类型,因为它不是委托类型。



无法将类型'string'隐式转换为bool。



这三个错误正在给出。



我如何解决这个错误?

请帮帮我。



先谢谢。



Ankit Agarwal

软件工程师

解决方案

尝试双倍==:

 objstudentdetail =(来自数据  objentity.studentdetails 
其中 data.studentid ==学生tId
选择数据).FirstOrDefault();


嗯。

尝试==而不是=?

 其中 data.studentid = StudentId 

成为

 其中 data.studentid == StudentId 


上面提到的错误: -

Quote:

无法将lambda表达式转换为类型'string',因为它不是委托类型



当错过了linq的命名空间时,有时会出现此错误

使用System.Linq; 使用System.Data.Entity;

Mehdi和Griff是绝对正确你错过了双等号,请记住并检查命名空间。有时候,由于命名空间的原因,double equals也会抛出你提到的第一个错误。

希望无论如何都有帮助。

谢谢。

:)


Hello,

I am using this code in mvc for delete.

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

解决方案

Try a double == :

objstudentdetail = (from data in objentity.studentdetails
where data.studentid == StudentId
select data).FirstOrDefault();


Um.
Try "==" instead of "="?

where data.studentid = StudentId

Becomes

where data.studentid == StudentId


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.
:)


这篇关于如何解决无法将lambda表达式转换为类型'string',因为它不是委托类型。错误。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆