0

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?

johnny 5
  • 19,893
  • 50
  • 121
  • 195
  • Do you have to use dynamic linq? – Sam Leach Oct 22 '14 at 17:24
  • Yeah, my results sets are going to be created dynamically by the user to create reports and what not. If I do this with regular link I have to explicitly specify every property :/ – johnny 5 Oct 22 '14 at 17:26
  • Where you define method `GetFormattedLink`? – Grundy Nov 12 '14 at 08:30
  • I already solved this, It turns out you can't inject a function into Dynamic linq that is occuring on LinqToEntities if you want to see my solution lmk – johnny 5 Nov 12 '14 at 16:07

1 Answers1

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)

Matt Sanders
  • 953
  • 1
  • 13
  • 23
  • It cannot resolve the method still when moving it into 'FindBestMethod' – johnny 5 Oct 22 '14 at 18:09
  • Is 'FindBestMethod' the class name that 'GetFormattedLink' is in? If you post more of the class structure it might be easier to help you – Matt Sanders Oct 22 '14 at 19:51
  • FindBestMethod is internal to Dynamic.Linq dll it can't resolve any suitable methods it uses reflection to invoke the GetFormattedLink – johnny 5 Oct 22 '14 at 19:54