开发者

Chaining MapHierarchy() to add more Cases in EF code first

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 })
                      .AddA开发者_如何学CnotherFolder(this)
                      .ToTable("Folder");

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


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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜