【问题标题】:WCF and Linq ServiceWCF 和 Linq 服务
【发布时间】:2011-09-23 11:45:10
【问题描述】:

我正在使用 linq 制作 wcf 休息服务。我想使用存储过程来访问 linq 中的数据库..我开始了解访问语法但 ToList() 属性我在我的项目中找不到..有人可以建议我解决方案吗?


代码:[OperationContract] [WebGet(UriTemplate = "/CList/")] 公共 CList[] GetCList() {string strConnection = ConfigurationManager.ConnectionStrings["HConnectionString"].ConnectionString;

    HDataContext dc = new HDataContext(strConnection);

    string strUrl = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.ToString();

    var result = from cust in dc.tbl_Customer_Masters

                 select new CList
                 {
                     RMSID = 0,
                     CID = cust.C_Id,
                     FIRSTNAME = cust.C_First_Name,
                     LASTNAME = cust.C_Last_Name,

                 };

    return result.ToArray(); }

【问题讨论】:

  • 对不起 ToList() 属性*

标签: wcf linq service


【解决方案1】:

ToList() 方法 只为继承自System.Linq.Enumerable 或实现IEnumerable 接口的对象定义。因此,您需要确保以下几点:

  1. 您在项目中引用了相应的 DLL(它位于 System.Core 中,因此默认情况下您应该有一个引用,除非您将其删除)。
  2. 您的文件中有 System.Linq 命名空间的 using 指令。
  3. 您尝试调用ToList 的对象实际上继承自System.Linq.Enumerable 或实现IEnumerable 接口。

【讨论】:

  • System.Core 没有添加它的物理位置是什么?
  • 当我添加 system.core.dll 时出现错误:无法加载文件或程序集“System.Core”或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。
  • 您需要以 .NET 3.5 或更高版本为目标才能引用它。
【解决方案2】:

ToList 是一个Extension Method。这意味着它实际上不在包含类中。您需要在代码中添加 using 语句才能使用此功能。

using System.Linq;

然后你可以在任何 IEnumerable 上调用 ToList()

【讨论】:

  • 它默认添加到 VS 2008 项目中并且已经存在...然后我也找不到它..
猜你喜欢
  • 1970-01-01
  • 2011-03-23
  • 2011-06-13
  • 2018-08-17
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
相关资源
最近更新 更多