c# - 如何从 SQL to Linq 中的存储过程中进行选择

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

这可能吗?

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

当我运行此命令时,出现错误:

Could not find an implementation of the query pattern for source type 'System.Data.Linq.ISingleResult WcfService1.GetProcedurePersonasResult'.
'Select' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'?

我也有这个并且工作完美

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

最佳答案

如果您已经拥有

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

例如,您想从您可能执行的操作中选择特定的内容。

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

要序列化为 json,您可以使用

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

关于c# - 如何从 SQL to Linq 中的存储过程中进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12462564/

相关文章:

c# - 将带毫秒的 DateTime 插入 SQL Server

sql - 用于安装 SQL Server Express Management Studio 2008 的 Pb

sql-server - 插入中保留的文档中 XML 节点的顺序?

sql - 混合使用 ADO.NET 和 LINQ-TO-SQL 不好吗?我的数据层不工作

c# - 存储库模式和 MVC 帮助

c# - Assembly.GetCustomAttributes 仍然被认为是最佳方法吗?

c# - Azure 示例 4-1-MyOrg 引发 "HttpRequestException: Invalid status code in the HttpResponseMessage: Unauthorized."错误

C# - Get 和 Set 访问器中的树/递归?

mysql - tungsten replicator可以通过ODBC和标准SQL连接sqlserver吗?

linq-to-sql - 如何在没有 ORM 的情况下将 LINQ to SQL 与返回多个结果集的存储过程一起使用?