【发布时间】:2016-12-29 04:46:29
【问题描述】:
我只想从包含列 ID、Name、Gender 和 MarkUp 的简单表中返回一个名为 Name 的列。
当我运行以下代码时,出现以下错误:
无法将类型“System.Collections.Generic.List”隐式转换为“System.Collection.Generic.List”
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using SimpleWebApplication;
using System.Configuration;
namespace SimpleWebApplication
{
/// <summary>
/// Summary description for SimpleWebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class SimpleWebService : System.Web.Services.WebService
{
[WebMethod]
public List<tblStudent> getAllLINQ()
{
List<string> studentList = new List<string>();
try
{
using (TestingEntities database = new TestingEntities())
{
var studentData = (from table in database.tblStudents select table).Select(u => new { u.Name });
studentList = studentData.ToList();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return studentList;
}
}
}
【问题讨论】:
-
在 studentList = studentData.ToList() 处出错
-
您能否编辑问题以从文件顶部显示带有 using 语句的块?
标签: c# entity-framework linq