CS1929 C# 'RfcParameterClass' 不包含 'Cast' 的定义

CS1929 C# 'RfcParameterClass' does not contain a definition for 'Cast'

CS1929 C# 'RfcParameterClass' 不包含 'Cast' 的定义,最佳扩展方法重载 'ParallelEnumerable.Cast(ParallelQuery)' 需要类型为 'ParallelQuery'[ 的接收器=21=]

大家好,我正在制作一种适用于 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>();

如您所见,在您的 RfcParameterClass class 中没有定义名为 Cast 的方法,也没有接受 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();