views:

52

answers:

1

I'm hoping there will be a crazy linq answer to this, it feels like there should be

Current code:

MapHierarchy().Case<Folder>(f => new { FolderId = f.Id, 
                                        f.Name,
                                        Type = 1 })
                      .Case<RootFolder>(f => new { f.RootName,
                                                    Type = 2 })
                      .ToTable("Folder");

Another method:

void AddAnotherFolder(something)
{
   something.Case<RootFolder>(f => new { f.RootName, Type = 2 })
}

What I would like to be able to do is pass that method into the MapHierarchy string - is that possible?

Something like...

MapHierarchy().Case<Folder>(f => new { FolderId = f.Id, 
                                        f.Name,
                                        Type = 1 })
                      .Case<RootFolder>(f => new { f.RootName,
                                                    Type = 2 })
                      .AddAnotherFolder(this)
                      .ToTable("Folder");

It feels like a linq question, would be VERY cool if it could

+1  A: 

Look at the method signature for Case<T>. You should be able to create a similar extension method in a static class with where clauses for your particular types. It might look something like this:

public static class ExtensionClass
{
    public static HierarchyEntityMap<TEntity> AddAnotherFolder<TEntity>(this HierarchyEntityMapGenerator<TEntity> source) where TEntity:RootFolder
    {
       return source.Case<TEntity>(f => new { f.RootName, Type = 2 });
    }
}

And to call it you'll just do .AddAnotherFolder() without the (this).

[NOT TESTED, BUT IT WILL BE SOMETHING LIKE THAT]

Hightechrider