【问题标题】:C# LINQ-to-SQL Multiple selectsC# LINQ-to-SQL 多选
【发布时间】:2010-11-29 22:00:06
【问题描述】:

我知道了,它在我的 MS SQL 2008 数据库中调用了一个 SP:

[Function(Name = "dbo.Content_GetContent")]
    [ResultType(typeof(Content_GetContentResult))]
    [ResultType(typeof(Content_GetContentImagesResult))]
    [ResultType(typeof(Content_GetContentBoxesResult))]
    [ResultType(typeof(Content_GetContentSearchWordsResult))]
    public IMultipleResults GetContent([Parameter(DbType = "INT")]int? contentID)
    {
        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), contentID);
        return ((IMultipleResults)(result.ReturnValue));
    }

但是我遇到了 2 个问题,不是每个表都可能返回结果,如果提供的 contentID 不正确(不是有效的内容编号),那么它会失败并生成以下错误: “为不返回 IMultipleResults 的函数 'GetContent' 声明了多个结果类型。”

有什么办法解决这个问题吗?

【问题讨论】:

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


    【解决方案1】:

    您能否更改存储过程,以便在提供不正确的 contentID 时返回空表? (而不是返回一条消息或它现在做什么)

    如果您的存储过程不能保证每次都返回相同数量的表,那么您将需要花很长时间才能确定哪些表确实返回了......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 2011-04-20
      相关资源
      最近更新 更多