【发布时间】:2020-10-19 05:38:14
【问题描述】:
CS1929 C#“RfcParameterClass”不包含“Cast”的定义,最佳扩展方法重载“ParallelEnumerable.Cast(ParallelQuery)”需要“ParallelQuery”类型的接收器
大家好,我正在制作一种适用于 SAP RFC 连接器的方法。连接工作正常,我可以轻松地从 SAP 获取数据,但问题在于使用这些数据。 CS1929错误导致代码底部的查询。我想从这些数据中设置很多“MLFBCode”实例。任何人都可以帮助我吗?我正在使用 VS 16.7.3 和 .NET Core 3.1。非常感谢!
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using RFCCONNECTORLib;
using SmartLab_System.AppConfig;
using SmartLab_System.Models;
using RfcData = RFCCONNECTORLib.RfcParameterClass;
using RfcRow = RFCCONNECTORLib.RfcFields;
namespace SmartLab_System.Data
{
public static class RFCMethodsForSLS
{
private static NWRfcSession Session = new NWRfcSession();
//Info: https://rfcconnector.com/documentation/api/session/
public static bool WasConnected { get; private set; } = true;
public static Regex RegexPattern { get; private set; } = new Regex(Validation.MLFBLuke);
/// <summary>
/// Calls the "Connecting" method which returns wanted MLFB entries from SAP
/// </summary>
/// <param name="inputString">String which will be searched</param>
/// <param name="strLanguage">Set language "CS", "EN", "DE", ...</param>
/// <param name="maxRows">Set maximum returned rows count</param>
public static List<MLFBCode> GetMLFBData(string inputString, int maxRows = 100000, string strLanguage = "CS", string onlyIn4711 = "X")
{
string functionName = "/SIE/AD_ZPE_TL_MAT_INFO";
List<KeyValuePair<string, string>> inputParameters = new List<KeyValuePair<string, string>>();
List<string> outPutParameters = new List<string>();
inputParameters.Add(new KeyValuePair<string, string>("INPUT_STRING", inputString));
inputParameters.Add(new KeyValuePair<string, string>("LANG", strLanguage));
inputParameters.Add(new KeyValuePair<string, string>("ONLY_IN_4711", onlyIn4711));
outPutParameters.Add("MLFB"); // mlfb
outPutParameters.Add("MATNR"); // matnr (number)
outPutParameters.Add("MAKTG"); // text (description)
outPutParameters.Add("DEL_STAT"); // vymaz na urovni master dat - "X" means Deleted
outPutParameters.Add("DEL_STAT_WERK"); // vymaz na urovni zavodu - "X" means Deleted
outPutParameters.Add("DEL_DISPO_99"); // docasny vymaz na urovni disponenta - "X" means Deleted
outPutParameters.Add("DEL_STAT_LV"); // docasny vymaz statusem - "X" means Deleted
outPutParameters.Add("EXISTS_IN_4711"); // material zalozen pro nas zavod - "X" means was set for OEZ
RfcData data = (RfcData)Connecting(functionName, inputParameters);
List<MLFBCode> mLFBs = new List<MLFBCode>();
List<RFCOutputData> rFCOutputData = new List<RFCOutputData>();
mLFBs = (from RfcRow dataRow in data
select new MLFBCode()
{
MLFB = dataRow["MLFB"].ToString(),
Number = dataRow["MLFB"].ToString(),
Description = dataRow["MAKTG"].ToString(),
IdGroup = 1,
Active = true
}).ToList();
return mLFBs;
}
编辑问题 - 确定我添加了 Connecting(functionName, inputParameters) 方法代码:
private static Object Connecting(string functionName, List<KeyValuePair<string, string>> inputParameters)
{
Regex regex = new Regex(Validation.MLFB);
Object data = new { };
string[,] resultTableArray = new string[,] { };
SetRFC(); //Set login data
if (!Session.IsConnected)
{
Session.Connect(); //Connection to SAP
if (Session.IsConnected)
{
FunctionCall fn = Session.ImportCall(functionName); //Set call
foreach (KeyValuePair<string, string> param in inputParameters) //Inserting input parametters of the SAP function
{
fn.Importing[param.Key].value = param.Value;
}
Session.CallFunction(fn, true); //Calling the function
data = fn.Tables["RESULT_TABLE"]; //Getting data from SAP
}
else WasConnected = false;
}
if (WasConnected)
Session.Disconnect();
return data;
}
【问题讨论】:
-
Connecting(functionName, inputParameters)真正返回什么类型? -
它返回“对象数据 = fn.Tables["RESULT_TABLE"];"。 “表”是“RfcParameters IFunctionCall.Tables”