通过 LINQ-to-SQl 加载数据集

发布于 2024-11-06 09:25:17 字数 434 浏览 2 评论 0原文

我有一个返回 DataSet 的存储过程。该存储过程通过实体数据模型在我的 C# 代码中公开。如何在我的代码中获取数据集?上下文不断尝试自动生成一组强类型的对象。但是,这些对象仅代表第一个结果集。我的 DataSet 有 4 个结果集。这是我正在使用的代码:

using (DBDataContext context = new DBDataContext())
{
  var myDataSet = context.LoadData();   // Load data is the name of my sproc

  // how do I get a DataSet here?
}

How do I get a DataSet via LINQ-to-SQL, or LINQ-to-EntityDataModel, or无论它被称为?

非常感谢您的帮助

I have a stored procedure that returns a DataSet.This stored procedure is exposed in my C# code via an Entity Data Model. How do I get the DataSet in my code? The context keeps trying to automatically generate a strongly-typed set of objects. However, those objects only represent the first result set. My DataSet has 4 result sets in it. Here is the code I'm using:

using (DBDataContext context = new DBDataContext())
{
  var myDataSet = context.LoadData();   // Load data is the name of my sproc

  // how do I get a DataSet here?
}

How do I get a DataSet via LINQ-to-SQL, or LINQ-to-EntityDataModel, or whatever it is called?

Thank you very much for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咆哮 2024-11-13 09:25:17

如果您有多个结果集,那么您需要编写一些代码 - 但这并不难:

网上有一些示例 - 例如:

它们主要显示扩展您的部分内容所需的内容datacontext 类似于:

    <FunctionAttribute(Name:="dbo.GetMultipleSets")> _
    <ResultType(GetType(Type_1))> _
    <ResultType(GetType(Type_2))> _
    Public Function GetMultipleSets() As IMultipleResults
        Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo))
        Dim results As IMultipleResults = DirectCast(result.ReturnValue, IMultipleResults)
        Return results
    End Function

或在 C# 中类似于:

    [Function("dbo.GetMultipleSets"]
    [ResultType(typeof(Type_1))]
    [ResultType(typeof(Type_2))]
    public IMultipleResults GetMultipleSets()
    {
        IExecuteResult result = ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()));
        IMultipleResults results  = (IMultipleResults)result.ReturnValue;
        return results;
    }

希望对

Stuart有帮助

If you have multiple result sets then you need to write some code - but it's not hard:

There's a few examples out there on the web - e.g.:

They mostly show what's needed as extending your partial datacontext with something like:

    <FunctionAttribute(Name:="dbo.GetMultipleSets")> _
    <ResultType(GetType(Type_1))> _
    <ResultType(GetType(Type_2))> _
    Public Function GetMultipleSets() As IMultipleResults
        Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo))
        Dim results As IMultipleResults = DirectCast(result.ReturnValue, IMultipleResults)
        Return results
    End Function

or in C# as something like:

    [Function("dbo.GetMultipleSets"]
    [ResultType(typeof(Type_1))]
    [ResultType(typeof(Type_2))]
    public IMultipleResults GetMultipleSets()
    {
        IExecuteResult result = ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()));
        IMultipleResults results  = (IMultipleResults)result.ReturnValue;
        return results;
    }

Hope that helps

Stuart

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文