Llblgen and FOR XML PATH

Posts   
1  /  2
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39618
Joined: 17-Aug-2003
# Posted on: 31-Jan-2019 09:15:29   

To make it work in linq you need a custom extension method which is handled as a function mapping, as the linq provider itself doesn't know how to convert a custom method to a custom predicate nor are there extension points to add that. So to make this work, you effectively have to have a mapping for a .net method which converts to a FOR XML fragment. This is equivalent to the free text search fragment mapping as described in the docs: https://www.llblgen.com/Documentation/5.5/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Linq/gencode_linq_functionmappings.htm#full-text-search

Frans Bouma | Lead developer LLBLGen Pro
TomDog
User
Posts: 618
Joined: 25-Oct-2005
# Posted on: 31-Jan-2019 12:36:10   

Yes I already have some function mappings but I didn't think they could take a query as an argument. I tried this

new FunctionMapping(typeof(GeneralHelper), "JoinAsString", 1, "{0} for xml path('')")

but I got this error:

The parameter at position 0 is of an unsupported type: Query

public const string StringJoinSeperator = ", ";

public static string JoinAsString<T>(this IEnumerable<T> input)
{
            return JoinAsString(input, StringJoinSeperator);
}

public static string JoinAsString<T>(this IEnumerable<T> input, string separator)
{
            return input == null ? string.Empty : StringHelper.Join(separator, input.Select(i => Convert.ToString(i)));
}

    /// <summary>
    ///   Joins an array of non empty strings together as one string with a separator between each non empty original string.
    /// </summary>
    /// <param name="separator">The separator.</param>
    /// <param name="values">The values.</param>
    /// <returns></returns>
public static string Join(string separator, IEnumerable<string> values)
{
      return string.Join(separator, values.Where(s => !string.IsNullOrEmpty(s)));
}

Jeremy Thomas
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39618
Joined: 17-Aug-2003
# Posted on: 31-Jan-2019 16:36:50   

That's correct, it's a crude way to get some fragments working, but what you want is that the query you specify is first evaluated, and then passed as an argument. It doesn't get that far, simply because function mappings are evaluated before query evaluation. So you can't pass a query as an argument to a function mapping (cyclic dependency).

So I'm afraid it's not going to work what you want. I should have realized that when I replied, I didn't look closely at your example query. flushed

Frans Bouma | Lead developer LLBLGen Pro
1  /  2