无法转换LInq的return语句,它给出了错误“无法隐式转换类型system.collections.generic.list<匿名类型#1> to system.collections.generic.IList< Student>", [英] unable to convert the return statement Of LInq, It gives the error "cannot implicitly convert type system.collections.generic.list<Anonymous Type#1> to system.collections.generic.IList<Student>",

查看:80
本文介绍了无法转换LInq的return语句,它给出了错误“无法隐式转换类型system.collections.generic.list<匿名类型#1> to system.collections.generic.IList< Student>",的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公共班学生:BaseEntity

{

#region fields

public string StudentID {get;组; } $ / $


public string FirstName {get; set;}



public string LastName {get;组; }



public int Age {get;组; }



public string Gender {get;组; } $ / $


public string Batch {get;组; }



公共字符串地址{get;组; }









#endregion

}



公共虚拟IList< student> GetStudentByID()

{



var query =来自c in _studentRepository.Table

orderby c.StudentID

选择新的

{c.StudentID,

c.FirstName,

c.LastName,

c.Age

};



var details = query.ToList();

返回细节;



}

public class Student:BaseEntity
{
#region fields
public string StudentID { get; set; }

public string FirstName{get;set;}

public string LastName { get; set; }

public int Age { get; set; }

public string Gender { get; set; }

public string Batch { get; set; }

public string Address { get; set; }




#endregion
}

public virtual IList<student> GetStudentByID()
{

var query = from c in _studentRepository.Table
orderby c.StudentID
select new
{ c.StudentID,
c.FirstName,
c.LastName,
c.Age
};

var details = query.ToList();
return details;

}

推荐答案





以上错误是自我探索,





解决方案:



Hi,

Above error is self exploratory,


Solution :

var query = from c in _studentRepository.Table
orderby c.StudentID
select new Student
{ StudentID=c.StudentID,
FirstName=c.FirstName,
LastName=c.LastName,
Age=c.Age
};





它会起作用。



it will work.


var query = from c in _studentRepository.Table
orderby c.StudentID
select new Student
{ StudentID=c.StudentID,
FirstName=c.FirstName,
LastName=c.LastName,
Age=c.Age
};







实现上面的代码之后,它给出错误为无法初始化类型'学生'并且集合初始化因为它没有实现'System.Collections.IEnumerable'




After Implementing the Above code it gives error as " Cannot Initialize type 'Student' with a collection initialize beacuse it does not implement 'System.Collections.IEnumerable' "


这篇关于无法转换LInq的return语句,它给出了错误“无法隐式转换类型system.collections.generic.list&lt;匿名类型#1&gt; to system.collections.generic.IList&lt; Student&gt;&quot;,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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