Dynamic Linq Execute Functions inside of Select Statement

a 夏天 提交于 2020-01-07 06:19:48

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/26513247/dynamic-linq-execute-functions-inside-of-select-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!