问题描述
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;
}
解决方法
相信您使用的图书馆是RFCConnector。
但是值得一提的是
from RFCRow row in data
“ 预编译”为此C#代码
data.Cast<RFCRow>();
正如您所看到的,在您的Cast
类中没有定义称为RfcParameterClass
的方法,也没有同名的扩展方法可以接受RFCParameterClass
类型第一个参数,因此它不会编译。我想您需要执行以下操作:
from RfcRow row in data.Rows
更新
要获得一行的实际值,您需要对此调用value
,因此您的代码将如下所示:
(from RfcRow dataRow in data.Rows
select new MLFBCode()
{
MLFB = dataRow["MLFB"].value.ToString(),Number = dataRow["MLFB"].value.ToString(),Description = dataRow["MAKTG"].value.ToString(),IdGroup = 1,Active = true
}).ToList();