【问题标题】:How to select from a stored procedure in SQL to Linq如何从 SQL 中的存储过程中选择到 Linq
【发布时间】:2012-09-17 15:33:46
【问题描述】:

这可能吗?

...
Int32? Id = 1;
QDataContext qDataContext = new QDataContext();
var q= from p in qDataContext.GetProcedurePersonas(Id) 
       select p.name, p.last;
...

当我运行这个时,我得到一个错误:

找不到源类型的查询模式的实现 'System.Data.Linq.ISingleResult WcfService1.GetProcedurePersonasResult'。
未找到“选择”。您是否缺少对“System.Core.dll”的引用 还是“System.Linq”的 using 指令?

我也有这个并且完美地工作

...
Int32? Id = 1;
QDataContext qDataContext = new QDataContext();
var q= qDataContext.GetProcedurePersonas(Id);
...

【问题讨论】:

  • 不管有没有可能,你为什么不试试呢?
  • 如果返回类型是一个集合,那么是的,它应该是可能的。
  • 根据您发布的内容,我假设您已经实施了 SP,因此正如 @MiklosBalogh 所建议的,您为什么不先自己尝试一下?
  • 我想要结果 json 序列化 linq

标签: c# sql-server linq-to-sql stored-procedures


【解决方案1】:

如果你已经拥有了

QDataContext qDataContext = new QDataContext();
var q= qDataContext.GetProcedurePersonas(Id);

例如,您想从 q 中选择特定的内容,您可能会这样做。

var specific=(from c in q where c.columnvalue == yourValue select c.columnvalue).ToList();

序列化为你可以使用的json

 JavaScriptSerializer jss = new JavaScriptSerializer();
    string json = jss.Serialize(specific);

【讨论】:

  • 我还需要包括“使用 System.Linq”;由于某种原因没有出现在我的系统中。再见! ...多谢了..!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 1970-01-01
  • 2014-12-07
  • 1970-01-01
  • 2010-12-10
  • 1970-01-01
相关资源
最近更新 更多