动态Linq在Select语句中执行函数 [英] Dynamic Linq Execute Functions inside of Select Statement

查看:137
本文介绍了动态Linq在Select语句中执行函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个声明的函数:

pre $ public static string GetFormattedLink(string ExtTitleID)
{
returnStr_+ ExtTitleID;



$ b $ p
$ b

我如何从动态Linq中的Select语句执行此语句我试过了。

 使用(var Model = new MK3Entities())
{
var TOrigin =(Model.Titles .Where(ID> 19632)
.Select(new(ID,GetFormattedLink(ExtTitleID)))
as System.Collections.IEnumerable)
.Cast< dynamic>( )。取(10).ToList();






$ b然而,这会返回异常:没有适用的方法'GetFormattedLink'存在于'标题'类型中。



如何在Select中格式化我的结果?

解决方案

看起来范围是在没有GetFormattedLink的标题上,如果它不在Title类上,请尝试使用完整名称空间调用该方法(或者将它移动到标题类if那就是它的所在)


I'm trying to grab out formatted values from a project.

I have a function declared:

public static string GetFormattedLink(string ExtTitleID)
{
    return "Str_" + ExtTitleID;
}

How would I execute this statement from the Select Statement in Dynamic Linq I tried.

using (var Model = new MK3Entities())
{
    var TOrigin = (Model.Titles.Where("ID > 19632")
                               .Select("new(ID,  GetFormattedLink(ExtTitleID))") 
                                as System.Collections.IEnumerable)
                               .Cast<dynamic>().Take(10).ToList();

}

However this returns the Exception: No applicable method 'GetFormattedLink' exists in type 'Title'.

How can I Formatted my results inside of the Select?

解决方案

It looks like the scope is on title which does not have the "GetFormattedLink", try calling that method with the full namespace if it is not on the Title class (or move it to the title class if that is where it belongs)

这篇关于动态Linq在Select语句中执行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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