不知道如何将转换对象结果转换为通用列表 [英] Dont know how to convert convert object result into generic list
问题描述
大家好
新的Generic,我不知道如何兑换这个
public partial class Student
{
public int Id {get;组; }
公共字符串StudentCode {get;组; }
public string StudentName {get;组; }
public string Department {get;组; }
public string Address {get;组; }
}
public virtual ObjectResult< sp_StudentDetails_Result> sp_StudentDetails(字符串操作)
{
var actionParameter = action!= null?
new ObjectParameter(Action,action):
new ObjectParameter(Action,typeof(string));
return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction< sp_StudentDetails_Result>(sp_StudentDetails,actionParameter);
}
现在我尝试了这一个
列表< Student> student = new List< Student>();
使用(StudentEntities myDBEnty = new StudentEntities())
{
student = myDBEnty.Students.ToList();
student = myDBEnty.sp_StudentDetails(SELECT);
}
返回Json(学生,JsonRequestBehavior.AllowGet);
我想要退货,我收到的错误就像
严重级代码描述项目文件行抑制状态
错误CS0029无法隐式转换类型'System.Data.Entity.Core.Objects.ObjectResult< WebApplication2.Models.Data.sp_StudentDetails_Result>'到'System.Collections.Generic.List< WebApplication2.Models.Data.Student>'WebApplication2 E:\ MVV Test \ WebApplication2 \ WebApplication2 \Controllers \HomeController.cs 46 Active
怎么做这个
谢谢
我尝试了什么:
在谷歌上搜索并做了一些样本我无法成功
我有一段时间没有使用EF工作,但是可以为POCO(Plain Old Clr Objects)生成包装代码,所以需要重新制作。
否则,更改:student = myDBEnty.sp_StudentDetails( SELECT);
To :
var result = myDBEnty.sp_StudentDetails( SELECT);并在之后设置断点。现在使用Locals窗口查看
result
变量的内容。现在您可以看到需要完成哪些工作。
这是一个很好的资源: entityframeworktutorial.net [ ^ ]
Hi All
Am new in Generic , i dont know how to convert this one
public partial class Student { public int Id { get; set; } public string StudentCode { get; set; } public string StudentName { get; set; } public string Department { get; set; } public string Address { get; set; } }
public virtual ObjectResult<sp_StudentDetails_Result> sp_StudentDetails(string action) { var actionParameter = action != null ? new ObjectParameter("Action", action) : new ObjectParameter("Action", typeof(string)); return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<sp_StudentDetails_Result>("sp_StudentDetails", actionParameter); }
now i tried with this one
List<Student> student = new List<Student>(); using (StudentEntities myDBEnty = new StudentEntities()) { student = myDBEnty.Students.ToList(); student = myDBEnty.sp_StudentDetails("SELECT"); } return Json(student, JsonRequestBehavior.AllowGet);
and i want to return and i got error like
Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'System.Data.Entity.Core.Objects.ObjectResult<WebApplication2.Models.Data.sp_StudentDetails_Result>' to 'System.Collections.Generic.List<WebApplication2.Models.Data.Student>' WebApplication2 E:\MVC Test\WebApplication2\WebApplication2\Controllers\HomeController.cs 46 Active
how to do this one
Thanks
What I have tried:
tried in googling and did some sample i can't make it
I have not done work with EF for a while but it was possible to generate code to wrap for POCOs (Plain Old Clr Objects) so do recasting was required.
Otherwise, change:student = myDBEnty.sp_StudentDetails("SELECT");To:
var result = myDBEnty.sp_StudentDetails("SELECT");and set a breakpoint after. Now use the Locals window to view the contents of
result
variable. Now you can see what work needs to be done.
This is a good resource for you: entityframeworktutorial.net[^]
这篇关于不知道如何将转换对象结果转换为通用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!