如何在查询操作中使用我自己的方法 [英] how to use my own method in query operation

查看:95
本文介绍了如何在查询操作中使用我自己的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当我在select()方法中使用我自己的方法时,发生了错误。


我写了一个简单的方法  for test。功能是:


public static string getsuper(string a)

{

     ;        if(a.Equals(" bbb"))return" cc";
            if(a.Equals(" ddd"))return" mm";
           返回null;


}


在main()中,我写道:


  IQueryable的<串GT; res =  context.FromDsc< LineRecord>(" test")。选择(r => getsuper(r.Line));


  foreach(res中的字符串s)

  Console.WriteLine(s);


该程序在debuged时有一些错误。这个函数和main()在同一个类中。


有关错误的信息是:


Microsoft.Hpc.Linq.HpcLinqException未处理

  Message =创建此HpcLinqQuery(T)的作业失败,错误:JM错误:任务在执行期间失败,退出代码为-2096496617。请在任务的输出中检查错误详细信息..

&NBSP;来源= Microsoft.Hpc.Linq

  ErrorCode = 16777237

  StackTrace:

      在Microsoft.Hpc.Linq.HpcLinqQuery`1.CheckAndInitialize()

      在Microsoft.Hpc.Linq.HpcLinqQuery`1.GetEnumerator()

      在Microsoft.Hpc.Linq.HpcLinqQuery`1.GetEnumerator()

      在MyTest.Simple.Main(String [] args)位置C:\ Users \wyf \ Files \ Visual Studio 2010 \Projects \ MyTest \ MyTest \Program.cs:行号56
      在System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)

      在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

      在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)

      在System.Threading.ThreadHelper.ThreadStart()

  InnerException:


我不熟悉DryadLINQ,我该怎么做才能解决这个问题?


谢谢

解决方案

目前它看起来像IQueryable< string>的返回数据不能包含null。以下方法有效。


public static string getsuper(string a)

{

if(a.Equals(" bbb") ;))返回"cc";

if(a.Equals(" ddd"))return" mm"; $
return"";


}


您还可以修改查询以过滤掉不需要的值。其中(r =>!String.IsNullOrEmpty(r))


Hi,

When i using my own method in select() method ,an error occured.

I wrote a simple method  for test.The function is:

public static string getsuper(string a)
{
            if (a.Equals("bbb")) return "cc";
            if (a.Equals("ddd")) return "mm";
            return null;

}

And in the main() ,I wrote this:

 IQueryable<string> res =  context.FromDsc<LineRecord>("test").Select(r => getsuper(r.Line));

 foreach (string s in res)
 Console.WriteLine(s);

The program has some errors when debuged.This function and the main() are in the same class.

The information about the error is:

Microsoft.Hpc.Linq.HpcLinqException was unhandled
  Message=The job to create this HpcLinqQuery(T) failed with error: JM error: 任务在执行期间失败,退出代码为 -2096496617。请在任务的输出中检查错误详细信息。.
  Source=Microsoft.Hpc.Linq
  ErrorCode=16777237
  StackTrace:
       在 Microsoft.Hpc.Linq.HpcLinqQuery`1.CheckAndInitialize()
       在 Microsoft.Hpc.Linq.HpcLinqQuery`1.GetEnumerator()
       在 Microsoft.Hpc.Linq.HpcLinqQuery`1.GetEnumerator()
       在 MyTest.Simple.Main(String[] args) 位置 C:\Users\wyf\Documents\Visual Studio 2010\Projects\MyTest\MyTest\Program.cs:行号 56
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException:

I am not familiar with the DryadLINQ,what should i do to solve this?

thanks

解决方案

Currently it looks like returned data of IQueryable<string> cannot contain null. The following will work.

public static string getsuper(string a)
{
if (a.Equals("bbb")) return "cc";
if (a.Equals("ddd")) return "mm";
return "";

}

You could also modify your query to filter out unwanted values .Where(r => !String.IsNullOrEmpty(r))


这篇关于如何在查询操作中使用我自己的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆