Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#如何在接口中传递Linq-MarshalByRefObject_C#_Linq_Interface_Marshalbyrefobject - Fatal编程技术网

C#如何在接口中传递Linq-MarshalByRefObject

C#如何在接口中传递Linq-MarshalByRefObject,c#,linq,interface,marshalbyrefobject,C#,Linq,Interface,Marshalbyrefobject,这是这里的后续问题,但性质完全不同。我之所以提到它是因为我想提供前提 基本上,我将有一些数据表(或序列化类),它们将包含超过一百万行,并且很难从SQL返回 因此,使用我发现的一个示例,我使用MarshalByRefObject导出了一个TCP Channelservices来返回前x行。然而,对于我想做的事情来说,这真的不够强大。我对下面的代码很好奇,我如何为我的接口提供一个LINQ语句,这样我就可以对我的数据表运行任何LINQ 谢谢 代码使用-创建两个VS解决方案-启动服务器,启动客户端 --

这是这里的后续问题,但性质完全不同。我之所以提到它是因为我想提供前提

基本上,我将有一些数据表(或序列化类),它们将包含超过一百万行,并且很难从SQL返回

因此,使用我发现的一个示例,我使用
MarshalByRefObject
导出了一个TCP Channelservices来返回前x行。然而,对于我想做的事情来说,这真的不够强大。我对下面的代码很好奇,我如何为我的接口提供一个LINQ语句,这样我就可以对我的数据表运行任何LINQ

谢谢

代码使用-创建两个VS解决方案-启动服务器,启动客户端

---
服务器

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Data;
using System.Linq;

class Program
{


    public static DataTable myTimetable { get; set; }
    public static string[] myVars1 = { "apples", "pears", "peaches" };
    public static string[] myVars2 = { "bears", "lions", "eagles" };
    public static string[] myVars3 = { "car", "truck", "train" };
    public static string[] myVars4 = { "bat", "ball", "glove" };
    public static string[] myVars5 = { "lawyer", "court", "state" };
    public static Random rand1 = new Random();
    public static Random rand2 = new Random();
    public static Random rand3 = new Random();

    static void Main(string[] args)
    {
        DataObjectsServer();
    }
    static void DataObjectsServer()
    {
        Console.WriteLine("Data Objects server started...");

        myTimetable = new DataTable();
        myTimetable.Columns.Add("Col1");
        myTimetable.Columns.Add("Col3");
        myTimetable.Columns.Add("Col4");
        myTimetable.Columns.Add("Col5");
        myTimetable.Columns.Add("Col2");
        myTimetable.Columns.Add("Col6");


        for (int i = 0; i < 1000000; i++)
        {

            int test1 = rand1.Next(0, 2);
            int test3 = rand2.Next(0, 2);
            int test2 = rand3.Next(0, 2);
            DataRow dt = myTimetable.NewRow();
            dt[0] = myVars3[test1];
            dt[1] = myVars1[test2];
            dt[2] = myVars2[test3];
            dt[3] = myVars3[test2];
            dt[4] = myVars5[test1];
            dt[5] = myVars4[test3];
            myTimetable.Rows.Add(dt);
        }

        TcpChannel tcpChannel = new TcpChannel(9998);
        ChannelServices.RegisterChannel(tcpChannel);

        Type commonInterfaceType = Type.GetType("DataObjects");

        RemotingConfiguration.RegisterWellKnownServiceType(commonInterfaceType,
        "DataObjectsServer", WellKnownObjectMode.SingleCall);

        System.Console.WriteLine("Press ENTER to quitnn");
        System.Console.ReadLine();

    }

}

public interface DataObjectsServerInterface
{
    DataTable GetMyDataRows(int topXRow);

    //how do I provide a linq arguement!?!?
}

public class DataObjects : MarshalByRefObject, DataObjectsServerInterface
{

    public DataTable GetMyDataRows(int topxRow)
    {
        Console.WriteLine("X Row Request: " + topxRow);

        return Program.myTimetable.AsEnumerable().Take(topxRow).CopyToDataTable();

    }
}

这不就是为什么吗?@RobertMcKee我想-我的方法是在大约.2秒内解析100万条记录,然后返回3个类。这是在本地IIS Web服务器上运行的。可能要签出ODATA,连接测试并查看是否更喜欢它不应超过一个小时。它肯定会更加通用,并且可能在引导时表现更好。这不是我的目的吗?@RobertMcKee我猜-我的方法是在大约0.2秒内解析100万条记录并返回3个类。这是在本地IIS Web服务器上运行的。可能要签出ODATA,连接测试并查看是否更喜欢它不应超过一个小时。它肯定会更加通用,并且可能在开机时表现更好。
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Data;

class MyClient
{
    public static void Main()
    {
        TcpChannel tcpChannel = new TcpChannel();
        ChannelServices.RegisterChannel(tcpChannel);

        Type requiredType = typeof(DataObjectsServerInterface);

        DataObjectsServerInterface remoteObject = (DataObjectsServerInterface)Activator.GetObject(requiredType,
        "tcp://localhost:9998/DataObjectsServer");

        DataTable dt = remoteObject.GetMyDataRows(100);

        Console.WriteLine("rows received:" + dt.Rows.Count);
        Console.ReadLine();
    }
}
public interface DataObjectsServerInterface
{
    DataTable GetMyDataRows(int topXRow);

    //how do I provide a linq arguement!?!?
}